【发布时间】:2019-08-29 23:05:43
【问题描述】:
我创建了一个闪亮的应用程序,其中基于用户选择的参数有多个输出(表格、图表和文本)。我想下载 HTML 文档中的输出。我可以使用https://shiny.rstudio.com/articles/generating-reports.html 上的小示例来做到这一点,但我似乎无法弄清楚如何在降价文件中使用多个输出。
我环顾四周,虽然有一些例子,但我似乎仍然无法弄清楚。可能只是我经验不足。我在下面修改(很差)的代码给出了输出test.text、test.text2,然后又是test.text。
我希望能够添加随后将在降价中使用的多个输出值。我在反应函数中使用了我的所有输出,因为我注意到我不能在 downloadHandler 中使用 output$
这是我在downloadHandler中尝试使用的代码
test.text <- reactive({input$gendertext}) #input text written in boxes
test.text2 <- reactive({input$agetext})
output$report <- downloadHandler(
filename = "report.html",
content = function(file) {
tempReport <- file.path(tempdir(), "report.Rmd")
file.copy("report.Rmd", tempReport, overwrite = TRUE)
params <- list(n = test.text())
params2 <- list(n = test.text2())
rmarkdown::render(tempReport, output_file = file,
params = c(params,params2),
envir = new.env(parent = globalenv()))
}
)
由于我有多个输出(ggplots、表格和文本),我希望能够在 markdonw 中使用test.text、test.text2、plot1...plotn 等。分开。
例如
---
title: "Dynamic report"
output: html_document
params:
n: NA
---
```{r}
test.text
plot1
``
```{r}
test.text2
plot2
``
如果有更简单的方法可以从闪亮的 UI 下载 Html/pdf 文件,那就太棒了!
谢谢!
【问题讨论】:
标签: r shiny r-markdown