我很难在基于Rmarkdown的应用程序中获得ggvis和闪亮的功能。即使不使用bind_shiny
和ggvisOutput
(如here所示),我也可以创建以下ggvis数字:
---
title: "test"
runtime: shiny
output: html_document
---
```{r setup, include=FALSE}
require(ggvis)
knitr::opts_chunk$set(echo = TRUE)
```
```{r static}
inputPanel(
sliderInput('n', 'n:', min = 10, max = 100, value = 50),
actionButton('run', 'Run!')
)
data = data.frame(x = rnorm(50))
data %>%
ggvis(~x) %>%
layer_histograms()
```
但是,我正在构建动态报告,以允许用户配置输入数据,然后通过点击'运行'重新执行。按钮,像这样:
```{r config}
inputPanel(
sliderInput('n', 'n:', min = 10, max = 100, value = 50),
actionButton('run', 'Run!')
)
data = eventReactive(input$run, { data = data.frame(x = rnorm(input$n)) })
data %>%
ggvis(~x) %>%
layer_histograms()
```
当我尝试运行文档时,我收到了不明白的错误Quitting from lines 26-36 (test.Rmd)
。任何人都知道如何使这个工作?
更新:
这几乎可行,但是当我点击“跑”时,' ggvis绘图在单独的浏览器窗口中而不是在文档中呈现:
```{r config}
inputPanel(
sliderInput('n', 'n:', min = 10, max = 100, value = 50),
actionButton('run', 'Run!')
)
data = eventReactive(input$run, { data = data.frame(x = rnorm(input$n)) })
renderTable({summary(data())})
renderPlot({
data() %>%
ggvis(~x) %>%
layer_histograms() %>%
bind_shiny('plot')
})
ggvisOutput('plot')
```
答案 0 :(得分:1)
您链接的两个问题表明您需要' ggvis'代码在reactive({
内,而不是renderPlot({
现在这对我有用
---
title: "test"
runtime: shiny
output: html_document
---
```{r config}
library(ggvis)
inputPanel(
sliderInput('n', 'n:', min = 10, max = 100, value = 50),
actionButton('run', 'Run!')
)
data = eventReactive(input$run, { data = data.frame(x = rnorm(input$n)) })
renderTable({summary(data())})
reactive({
data() %>%
ggvis(~x) %>%
layer_histograms() %>%
bind_shiny('plot')
})
ggvisOutput('plot')
```