Generate pdf from html output

I have a shiny application which generates an html report in the UI and I would like to download this html report as a pdf.

I was using the chrome pagedown package which works locally but not on my linux server as part of RSConnect (documented issue). I'm looking for another way to generate a pdf from this html document produced as part of the dfSummary function.

Here is the reprex which provides the report called 'out' which I would like to download as a pdf. Any suggestions on making this work are appreciated:

library(shiny)
library(summarytools)
library(dplyr)
library(htmltools)

ui <- fluidPage(
  downloadButton("downloadReport", "Download PDF Report")
)

# Shiny app server
server <- function(input, output) {

  # Generate PDF report
  output$downloadReport <- downloadHandler(
    filename = "Summary.pdf",
    content = function(file) {
      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)

      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
      print(str(out))
      out
      out <- htmlOutput(out)

      temp <- tempfile(fileext = ".html")
      writeLines(as.character(temp), con = temp)
      rmarkdown::render(temp, output_format = "pdf_document", output_file = file,
                        envir = new.env(parent = globalenv()))
})
}
# Run the Shiny app
shinyApp(ui, server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.