问题描述
我有一个大型的Shiny应用程序,我想提供导出flexdashboard报告的可能性.因此,我添加了一个downloadHandler,它将某些参数传递给flexdashboard. Flexdashboard本身应在不部署在服务器上的情况下工作,因此我不使用runtime: shiny
选项.
I have a large Shiny app, and I would like to provide the possibility to export a flexdashboard report. Thus, I added a downloadHandler which passes certain params to the flexdashboard. The flexdashboard itself should work without being deployed on a server, thus I do not use the runtime: shiny
option.
如何将反应值传递给flexdashboard?如果我执行类似params <- list(y = test())
的操作,则报告创建会中断.
How can I pass reactive values to the flexdashboard? If I do something like params <- list(y = test())
, the report creation breaks.
服务器的相关部分.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())
)
}
)
报告的相关部分.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())
I figured out what was the issue: The reactive I wanted to pass to flexdashboard was not properly created at the time of report creation, and this caused the report creation to break...Passing reactives works exactly the same way as reporting data.frames:params <- list(y = test())
这篇关于将反应堆传递给flexdashboard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!