如何在闪亮的应用程序中使用PDF文件嵌入数据表?

时间:2018-07-10 12:30:28

标签: html r pdf shiny dt

假设我有一个简单的闪亮应用程序,它返回了DT表:

library(DT)

ui <- basicPage(
  h2("The mtcars data"),
  DT::dataTableOutput("mytable")
)

server <- function(input, output) {
  output$mytable = DT::renderDataTable({
    mtcars
  })
}

shinyApp(ui, server)

现在,我在最后一列中有要添加为嵌入式pdf的pdf文档。 可以说pdf文件的名称是myfile.pdf,myfile2.pdf,myfile3.pdf ... 我希望桌子看起来像

column1...|columnn|pdfdocument
A         |b      |myfile.pdf
C         |d      |myfile2.pdf
...

我尝试过:

server <- function(input, output) {
  mtcars <- cbind(mtcars, tags$embed(srce = "myfile.pdf"))
  output$mytable = DT::renderDataTable({
    mtcars
  })

但它返回:

cannot coerce class ‘"shiny.tag"’ to a data.frame

如何将可下载的pdf文件嵌入DT数据框

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。 首先,我从API下载pdf文档。然后,我将该文档复制到www文件夹中:

file.copy("pdfContent", paste0("www/", "pdfPath"))

之后,我创建了具有pdf内容的链接:

pdf_links <- paste0('<a href="', "pdfpath.pdf,' target="blank">PDF</a>')

并将其添加到DT表中。

相关问题