【问题标题】:How to embedd pdf file to data table using in shiny app?如何使用闪亮的应用程序将 pdf 文件嵌入到数据表中?
【发布时间】:2018-12-18 07:15:00
【问题描述】:

假设我有一个简单的闪亮应用程序,它返回 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 数据帧中

【问题讨论】:

    标签: html r pdf shiny dt


    【解决方案1】:

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

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

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

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

    并将其添加到 DT 表中。

    【讨论】:

      猜你喜欢
      • 2019-01-08
      • 2017-12-22
      • 2020-10-21
      • 2018-11-06
      • 2014-04-11
      • 1970-01-01
      • 2016-04-05
      • 2016-01-06
      • 1970-01-01
      相关资源
      最近更新 更多