我正在使用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')
```
答案 0 :(得分: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
的一大卖点就是不必编写一堆Shiny样板文件。 :其中如果这可以解决另一条路线仍然很好奇。