如何使用DataTable在Shiny中以可下载的PDF格式显示图像?

时间:2018-06-13 14:54:15

标签: r datatables shiny dt

我有以下数据集:

catalogue <- data.frame(Code = c("001", "002", "003", "004", "005", "006", "007", "008"),
                    Product = c("Prod1", "Prod2", "Prod3", "Prod4", "Prod5", "Prod6", "Prod7", "Prod8"),
                    Quantity = c(3, 1, 26, 4, 2, 2, 4, 2),
                    Picture = c("https://i.imgur.com/d2ZWLVx.png",
                                "https://i.imgur.com/d2ZWLVx.png",
                                "https://i.imgur.com/1NBDkl1.png",
                                "https://i.imgur.com/1NBDkl1.png",
                                "https://i.imgur.com/Z2DSLRq.png",
                                "https://i.imgur.com/YIHvU9B.png",
                                "https://i.imgur.com/e6lvBjQ.png",
                                "https://i.imgur.com/mb2CNX5.png"))

catalogue$Image = paste0('<img src = "', catalogue$Picture, '" height = "100"></img>')

这个闪亮的应用程序:

library(shiny)
library(tidyverse)
library(DT)

ui <- fluidPage(
        mainPanel(DTOutput("table1")))

server <- function(input, output, session){
             output$table1 <- renderDT(server = FALSE, {
                   catalogue %>% select(-Picture) %>%
                   DT::datatable(escape = FALSE, 
                                 rownames = FALSE,
                                 extensions = 'Buttons', 
                                 options = list(
                                            pageLength = 5,
                                            orientation ='landscape',
                                            dom = 'Bfrtip',
                                            buttons = c('pdf', 'print')))
                     })
                     }


shinyApp(ui, server)

当我在浏览器上打开应用程序时,会显示图像。但是,如果我尝试打印它或将其下载为PDF,则不会显示它们。任何人都知道如何解决它?

提前致谢!

0 个答案:

没有答案