【问题标题】:Pass reactives to flexdashboard将反应传递给 flexdashboard
【发布时间】:2019-12-30 09:25:06
【问题描述】:

我有一个大型 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)
```

【问题讨论】:

    标签: parameters shiny reactive flexdashboard


    【解决方案1】:

    我发现了问题所在:我想传递给 flexdashboard 的响应式在创建报表时没有正确创建,这导致报表创建中断...... 传递反应式的工作方式与报告 data.frames 完全相同: params &lt;- list(y = test())

    【讨论】:

      猜你喜欢
      • 2018-06-17
      • 2021-09-27
      • 1970-01-01
      • 2018-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-05
      • 2019-07-29
      相关资源
      最近更新 更多