I'm working on an automated reporting system using Quarto (flexdashboard) and Shiny. The idea is that users can upload data, interact with the dashboard to explore statistics, and then generate a PDF report that reflects their selected statistics.
Setup
My main Quarto file (main.qmd) is structured as a Shiny flexdashboard:
---
title: "Reporting Tool"
author: "XY"
output: flexdashboard::flex_dashboard
runtime: shiny
---
I have a separate Quarto file (pdf_file.qmd) that is responsible for generating the final PDF report. This file should receive selected input variables from the dashboard and render a report accordingly.
How I'm Calling the Report
In main.qmd, I trigger the report generation via downloadHandler:
output$download_report <- downloadHandler(
filename = function() {
paste0("microbiome-report-", Sys.Date(), ".pdf")
},
content = function(file) {
# Ensure correct path resolution
quarto_file <- normalizePath("src/pdf_file.qmd", mustWork = TRUE)
temp_output_dir <- tempfile()
dir.create(temp_output_dir, showWarnings = FALSE)
tryCatch({
# Render the Quarto report and specify output directory
quarto::quarto_render(
input = quarto_file,
output_format = "pdf",
output_file = "report.pdf",
output_dir = temp_output_dir,
execute_params = list(
physeq = isolate(reactive_phyloseq()),
metadata = isolate(uploaded_metadata()),
tax_level = isolate(input$tax_level),
metadata_group = isolate(input$metadata_group),
alpha_indices = isolate(input$alpha_indices)
)
)
# Copy the generated file to the correct location for download
file.copy(file.path(temp_output_dir, "report.pdf"), file, overwrite = TRUE)
}, error = function(e) {
print(paste("Error generating Quarto report:", e$message))
})
}
)
The Problem
- When I try to download the report, Quarto cannot find
pdf_file.qmdin thesrc/folder. - Running
normalizePath("src/pdf_file.qmd", mustWork = TRUE)in R returns the correct absolute path, but Quarto still throws an error. - The report does not generate, and I get:
Warning: Error in normalizePath: path[1]="src/pdf_file.qmd": The system cannot find the specified path
What I Tried
- Verified that
pdf_file.qmdexists insrc/ - Used absolute paths in
quarto_render() - Tested
quarto::quarto_render("src/pdf_file.qmd")manually (works fine outside Shiny) - Ensured
quarto::quarto_path()is correctly set up
Question
How can I properly call pdf_file.qmd from main.qmd in a Shiny + Quarto setup, ensuring that parameters are passed and the report generates correctly?
pdf_file.qmdin the same folder asmain.qmdorwwwfolder of the shiny app that is published/deployed.