Pass reactives to flexdashboard

夙愿已清 提交于 2020-06-17 08:16:13

问题


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.

How can I pass reactive values to the flexdashboard? If I do something like params <- list(y = test()), the report creation breaks.

Relevant part of 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())
    )
  }
)

Relevant parts of 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)
```

回答1:


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())



来源:https://stackoverflow.com/questions/57653627/pass-reactives-to-flexdashboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!