I created a shiny app in which I have multiple outputs (tables, graphs and text) based on user selected parameters. I would like to download the outputs in a HTML document. I am able to do this using the small example on https://shiny.rstudio.com/articles/generating-reports.html but I cannot seem to figure out how to use multiple outputs in the markdown file.
I looked around quite a bit and although there are some examples out there I still cannot seem to figure it out. Probably it's just me being inexperienced. The code I modified (poorly) bellow gives outputs test.text
, test.text2
then test.text
again.
I would like to be able to add multiple output values that will subsequently be used in the markdown. I am using all my outputs in reactive functions as I noticed that I cannot use output$
in downloadHandler
This is the code I am trying to use in 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()))
}
)
As I have multiple outputs (ggplots, tables and text) I would like to be able to use test.text
, test.text2
, plot1
...plotn
etc. in markdonw. separately.
e.g.
---
title: "Dynamic report"
output: html_document
params:
n: NA
---
```{r}
test.text
plot1
``
```{r}
test.text2
plot2
``
If there is an easier way to download an Html/pdf file from a shinyUI that would be amazing!
Thank you!