将反应传递给 flexdashboard
Pass reactives to flexdashboard
我有一个大型 Shiny 应用程序,我想提供导出 flexdashboard 报告的可能性。因此,我添加了一个 downloadHandler,它将某些参数传递给 flexdashboard。 flexdashboard 本身应该可以在不部署在服务器上的情况下工作,因此我 不 使用 runtime: shiny
选项。
如何将反应值传递给 flexdashboard?如果我执行类似 params <- list(y = test())
的操作,报告创建就会中断。
server.R的相关部分:
test <- reactive({
[[SOME STUFF]]
})
output$report <- downloadHandler(
# For PDF output, change this to "report.pdf"
filename = "report.html",
content = function(file) {
# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed).
tempReport <- file.path(tempdir(), "report.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)
# Set up parameters to pass to Rmd document
params <- list(y = test())
# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app).
rmarkdown::render(tempReport, output_file = file,
params = params,
envir = new.env(parent = globalenv())
)
}
)
report.Rmd的相关部分:
---
title: "Row Orientation"
output:
flexdashboard::flex_dashboard:
orientation: rows
params:
y: NA
---
```{r setup, include=FALSE}
library(flexdashboard)
library(ggiraph)
library(ggplot2)
library(magrittr)
```
Row
-------------------------------------
### Chart 1
```{r}
ggplot(params$y)
```
我明白了问题所在:我想传递给 flexdashboard 的反应在创建报告时没有正确创建,这导致报告创建中断...
传递反应式的工作方式与报告完全相同 data.frames:
params <- list(y = test())
我有一个大型 Shiny 应用程序,我想提供导出 flexdashboard 报告的可能性。因此,我添加了一个 downloadHandler,它将某些参数传递给 flexdashboard。 flexdashboard 本身应该可以在不部署在服务器上的情况下工作,因此我 不 使用 runtime: shiny
选项。
如何将反应值传递给 flexdashboard?如果我执行类似 params <- list(y = test())
的操作,报告创建就会中断。
server.R的相关部分:
test <- reactive({
[[SOME STUFF]]
})
output$report <- downloadHandler(
# For PDF output, change this to "report.pdf"
filename = "report.html",
content = function(file) {
# Copy the report file to a temporary directory before processing it, in
# case we don't have write permissions to the current working dir (which
# can happen when deployed).
tempReport <- file.path(tempdir(), "report.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)
# Set up parameters to pass to Rmd document
params <- list(y = test())
# Knit the document, passing in the `params` list, and eval it in a
# child of the global environment (this isolates the code in the document
# from the code in this app).
rmarkdown::render(tempReport, output_file = file,
params = params,
envir = new.env(parent = globalenv())
)
}
)
report.Rmd的相关部分:
---
title: "Row Orientation"
output:
flexdashboard::flex_dashboard:
orientation: rows
params:
y: NA
---
```{r setup, include=FALSE}
library(flexdashboard)
library(ggiraph)
library(ggplot2)
library(magrittr)
```
Row
-------------------------------------
### Chart 1
```{r}
ggplot(params$y)
```
我明白了问题所在:我想传递给 flexdashboard 的反应在创建报告时没有正确创建,这导致报告创建中断...
传递反应式的工作方式与报告完全相同 data.frames:
params <- list(y = test())