【问题标题】:ggvis with shiny runtime produces inconsistent output on EC2具有闪亮运行时的 ggvis 在 EC2 上产生不一致的输出
【发布时间】:2016-05-31 04:09:13
【问题描述】:

我正在使用 Rmarkdown、Shiny 和 ggvis 创建一个可配置的交互式报告。我在 Mac 上开发,然后部署到在 EC2 上运行 Ubuntu 的 Shiny 服务器。在 EC2 上,我的反应式 ggvis 绘图无法呈现,而只是回显反应式代码:

在本地,渲染反应图没有问题:

有人见过这个吗?是什么导致了不一致的行为?

此处为自包含示例:

---
title: "test"
runtime: shiny
output: html_document
---

```{r config}
require(ggvis)

inputPanel(selectInput('dataset', 'Data Set:', c('one', 'the other')),
           actionButton('run', 'Run!'))

data = eventReactive(input$run, {
  if (input$dataset == 'one') {
    data = data.frame(x = 1:20, y = rnorm(20))
  } else {
    data = data.frame(x = 1:20, y = rnorm(20, mean = 10, sd = 10))
  }
  return(data)
})  
```

```{r plot}
reactive({
  data() %>%
    ggvis(x = ~x, y = ~y) %>%
    layer_points(size := input_slider(min = 1, max = 100)) %>%
    bind_shiny('plot', 'plot_ui')
})

uiOutput('plot_ui')
ggvisOutput('plot')
```

【问题讨论】:

  • 它在本地和shinyapp.io上工作
  • 对,这就是问题所在。它可以在本地工作,但不能在 EC2 闪亮的服务器上工作。

标签: r amazon-ec2 shiny r-markdown ggvis


【解决方案1】:

我能够通过将所有内容包装到 Shiny App 中来产生正确的输出。

```{r shiny-app}
require(ggvis)

shinyApp(
  ui = fluidPage(
    inputPanel(selectInput('dataset', 'Data Set:', c('one', 'the other')),
           actionButton('run', 'Run!')),
    uiOutput('plot_ui'),
    ggvisOutput('plot')),

  server = function(input, output) {
    data = eventReactive(input$run, {
      if (input$dataset == 'one') {
        data = data.frame(x = 1:20, y = rnorm(20))
      } else {
        data = data.frame(x = 1:20, y = rnorm(20, mean = 10, sd = 10))
      }
      return(data)
    }) 

    output$plot = reactive({
      data() %>%
        ggvis(x = ~x, y = ~y) %>%
        layer_points(size := input_slider(min = 1, max = 100)) %>% 
        bind_shiny('plot', 'plot_ui')
    })
  },
  options = list(height = 500)
)
```

这解决了问题,但有点令人失望,因为使用ggvis 的一大卖点是不必编写一堆闪亮的样板。 :

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-01
    • 2017-03-15
    • 2015-06-23
    • 2016-02-22
    • 2014-09-17
    • 1970-01-01
    • 2014-06-19
    相关资源
    最近更新 更多