Print shiny html output as pdf or word

The following is rendered as an html output in my shiny application and I'd like the user to be able to print or save this document from the ui as a pdf or word. Any suggestions how to do this?

library(shiny)

ui <- fluidPage(
mainPanel(
htmlOutput("summary")
)
)

server <- function(input, output) {
output$summary <- renderUI({
x1 <- c("T", "T", "T", "T", "T", "T", "F", "F", "F", "N")
x2 <- c("A", "A", "A", "A", "A", "A", "A", "A", "A", "A")
x3 <- c(1,2,3,4,5,6,7,8,9,10)
x4 <- c(1,2,3,4,5,6,7,8,9,10)
d <- data.frame(x1,x2,x3,x4)

out <- print(arrange(dfSummary(d, round.digits = 3, max.distinct.values = 5), Variable), headings = FALSE, method = 'render', valid.col = F, footnote = "", bootstrap.css = FALSE)
})
}

shinyApp(ui = ui, server = server)

thank you

library(shiny)
library(summarytools)
library(tidyverse)
library(pagedown)
x1 <- c("T", "T", "T", "T", "T", "T", "F", "F", "F", "N")
x2 <- c("A", "A", "A", "A", "A", "A", "A", "A", "A", "A")
x3 <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
x4 <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
d <- data.frame(x1, x2, x3, x4)
 
out <- print(arrange(dfSummary(d,
                               round.digits = 3,
                               max.distinct.values = 5),
                     Variable),
             headings = FALSE,
             method = "render",
             valid.col = F,
             footnote = "",
             bootstrap.css = FALSE)




ui <- fluidPage(
  uiOutput("myout"),
  downloadButton("myd")
)

server <- function(input, output, session) {
  output$myout <- renderUI({
    out
  })
  
  output$myd <- downloadHandler(filename = function(){"myout.pdf"},
                                content = function(file){
                                  tf <- tempfile()
                                  writeLines(HTML(as.character(tags$html(tags$body(out)))),con = tf)
                                  chrome_print(input = tf,
                                               output = file,
                                               format = "pdf")
                                })
}

shinyApp(ui, server)
1 Like

once again, an awesome solution

thanks

This topic was automatically closed 7 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.