r-在Shiny中,如何以pdf格式显示带有下载按钮的html Rmd报告的缩略图



我需要以缩略图形式显示RMarkdown报告。第一个报告的封面是红色的,所以缩略图应该是红色的。黑色报告也是如此。我该怎么做?

此外,每一个都将与一个下载按钮相关联,该按钮将下载pdf格式的html文件。如何将下载按钮与html文件关联,以使下载成为pdf文件?

以下是我迄今为止所做的工作。有人帮忙吗?

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)

至少为了生成PDF,您需要有pagedown::chrome_print(input = 'www/red_report.html', output = file, format = 'pdf'),因为您需要将输出写入downloadHandler期望的文件中。

对于缩略图,你可以做这样的功能:

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)))))))

使用自定义labelbutton_linkbutton_label

最新更新