One can read in Chapter 9 Uploads and downloads | Mastering Shiny that:
RMarkdown works in the current working directory, which will fail in many deployment scenarios (e.g. on shinyapps.io). You can work around this by copying the report to a temporary directory when your app starts (i.e. outside of the server function):
However, the same section points to an example in Shiny - Generating downloadable reports where the temporary directory is used inside the server function.
So who's correct?
For example, would the following work on a server?
mod_download_server <- function(id, template_path, params = list()) {
moduleServer(id, function(input, output, session) {
output$report <- downloadHandler(
filename = "report.html",
content = function(file) {
report_path <- withr::local_tempfile(
lines = readr::read_file(template_path),
fileext = ".Rmd"
)
callr::r(
render_report,
list(input = report_path, output = file, params = params)
)
}
)
})
}