Help needed: generating downloadable reports in golem #970
-
Hi developers, I want to generate a downloadable HTML reports with golem. What I want to do is to included some generated tables and figures in the report. These tables and figures are produced in different shiny modules. How can I include them in Below is my minimal example. I know transform them into global variable should work. I am wondering if there is a suggested way under the golem framework? Thanks a lot. Dong library(shiny)
# UI
choice_ui <- function(id) {
ns <- NS(id)
tagList(
sliderInput(inputId = ns("slider"),
label = "Slider",
min = 1,
max = 100,
value = 50),
downloadButton(outputId = ns("report_button"),
label = "Generate report"
)
)
}
# Server
choice_server <- function(id) {
moduleServer(id, function(input, output, session){
output$report_button<- downloadHandler(
filename = "report.html",
content = function(file) {
tempReport <- file.path(tempdir(), "myRport.Rmd")
file.copy("www/myReport.Rmd", tempReport, overwrite = TRUE)
params <- list(n = input$slider,
mybar = barplot() # from another module
)
rmarkdown::render(tempReport, output_file = file,
params = params,
envir = new.env(parent = globalenv())
)
}
)
}
)
}
# Application
library(shiny)
app_ui <- function() {
fluidPage(
choice_ui("choice_ui_1")
)
}
app_server <- function(input, output, session) {
r <- reactiveValues()
choice_server("choice_ui_1")
}
shinyApp(app_ui, app_server) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey, You need to specify the correct path for the Rmd in your file.copy, to do that you can use the app_sys() wrapper located in app_config. For your example, it should be app_sys("app/www/myReport.Rmd") |
Beta Was this translation helpful? Give feedback.
Hey,
You need to specify the correct path for the Rmd in your file.copy, to do that you can use the app_sys() wrapper located in app_config.
For your example, it should be app_sys("app/www/myReport.Rmd")