Hi,
I have a shiny app which generates html outputs and I'd like to download this output as a pdf. I tried converting the data to an rmd and replacing a document on my www within the application, but the document does not update.
here's a reprex, does anyone have an idea how to do this? I tried chrome_print but it fails to work on linux (documented issue on github).
library(shiny)
library(summarytools)
library(dplyr)
library(htmltools)
library(quarto)
library(tinytex)
ui <- fluidPage(
downloadButton("downloadReport", "Download PDF Report")
)
server <- function(input, output) {
report <- shiny::reactive({
y1 <- c("T", "T", "T", "T", "T", "T", "F", "F", "F", "N")
y2 <- c("A", "B", "A", "B", "A", "B", "A", "B", "C", "D")
x3 <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
x4 <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
x5 <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
d <- data.frame(y1, y2, x3, x4, x5)
# Your existing code for generating the report
out <- print(arrange(dfSummary(d, round.digits = 3, max.distinct.values = 5), Variable),
headings = FALSE, method = 'render', valid.col = FALSE, footnote = "", bootstrap.css = FALSE)
out[[3]][[1]][[3]][[2]] <- NULL
})
# Generate PDF report
output$downloadReport <- downloadHandler(
filename = "my_report.pdf",
content = function(file) {
rmarkdown::render("www", output_file = file,
params = list(my_content = report()))
}
)
}
# Run the Shiny app
shinyApp(ui, server)