I have developed a Shiny app that runs a .qmd file as part of a download button. When I run the .qmd file it renders a 2 page pdf. When I host the app locally the download button works and i get a 2 page pdf. When post a shiny app to Posit Connect everything works except the download button. It does download a pdf, however it creates and extra page at the beginning with the title, deletes the subtitle, and bumps the contents down a page (i.e should be 2 pages and is now 3 pages).
output$downloadPDF <- downloadHandler(
filename = function() {
filename()
},
content = function(file) {
# Use withProgress to show a progress bar
withProgress(message = "Creating Report: ", value = 0, {
# Stage 1: Increment progress
incProgress(0.1, detail = "Collecting inputs...")
# Generate the Quarto params
params <- list(centercode = center_code(), organ = input$organ_code, filedate = as.character(Sys.Date()))
# debug params
print("Parameters for Quarto render:")
print(params)
# debug file path
# print(paste("Temporary output file path:", temp_output_dir))
print(paste("file name path:", filename()))
print(paste("Final output file path:", file))
incProgress(0.2, detail = "Building...")
tryCatch({
# Use Quarto's render function to create the PDF
quarto::quarto_render(
input = "NTS - Short Report - Typst App.qmd",
output_file = filename(),
output_format = "typst",
execute_params = params
)
incProgress(0.95, detail = "Downloading report...")
# Copy the generated file to the correct location for download
file.copy(filename(), file, overwrite = TRUE)
}, error = function(e) {
print(paste("Error generating Quarto report:", e$message))
})
}
)
}
)