In Shiny, how to display miniature/thumbnail of html Rmd report with download button in pdf?

Viewed 90

I need to display the RMarkdown Reports in thumbnails. The first report has a red cover, so the thumbnail should be red. The same for the black report. How can I do this?

In addition, each one will be associated with a download button that will download that html file in pdf. How can I associate download button to the html file, to make the download as a pdf file?

Below what I've done so far. Any help guys?

  library(shiny)

ui <- fluidPage(     

  htmlOutput(outputId = 'text_tab_2_comentario'),
  downloadButton("downloadData1", "Download Metrics Reports"),

  htmlOutput(outputId = 'text_tab_2_comentario2'),
  downloadButton("downloadData2", "Download Metrics Reports2")   
)

server <- function(input, output, session) {

  output$text_tab_2_comentario <- renderUI({

          tags$iframe(path = "www/red_report.html")
  })

  output$text_tab_2_comentario2 <- renderUI({
    tags$iframe(path = "www/black_report.html")

    })


output$downloadData1 <- downloadHandler(

    filename = function(){
        paste(Sys.time(), 'black_report.pdf')
    },

    content = function(file){
        pagedown::chrome_print('red_report.html', pdf)
    }
)

}

shinyApp(ui, server)
1 Answers

At least for generating the PDF, You need to have pagedown::chrome_print(input = 'www/red_report.html', output = file, format = 'pdf'), since you need to write the output into the file that the downloadHandler expects.

For the thumbnail, you could do something like this function:

https://github.com/jasdumas/shinyLP/blob/master/R/thumbnail_label.R#L15

  div(class = "row",
      div(class = "col-sm-14 col-md-12",
          div(class = "thumbnail",
              img(src = image, alt = "...",
                  div(class = "caption",
                      h3(label),
                      tags$iframe(path = "www/red_report.html"),
                      p(a(href = button_link,
                      class = 'btn btn-primary',
                      role = 'button',
                      button_label)))))))

With a custom label, button_link, button_label.

Related