【问题标题】:specify filename and header for datatable pdf output r shiny为数据表pdf输出指定文件名和标题r闪亮
【发布时间】:2018-08-13 15:21:24
【问题描述】:

我有一个像这样的闪亮应用:

library(shiny)
library(data.table)

tabledata <- data.table(a=1:4, b= 5:8)
ui <- fluidPage(
  dataTableOutput("currenttable")
)
server <-  function(input,output, session){
  output$currenttable <- renderDataTable({tabledata},rownames = FALSE, extensions = 'Buttons', 
                                         options = list(dom = 'Bfrtip',    buttons = c('copy', 'pdf'), 
                                                        filename = "CurrentTable", header= "My Header", pageLength = nrow(tabledata))
                                         )
}

shinyApp(ui, server)

pdf 按钮有效,但仅将文件保存为“pdf.pdf”而不是“CurrentTable”,并且缺少标题。

【问题讨论】:

    标签: r pdf datatable shiny


    【解决方案1】:
    1. 您需要bind the options to the pdf button。您可以通过这种方式包含filenameheader 选项。
    2. DataTable pdf referenceheader 指示表头(即列名)是否应包含在导出的表中——这只能是TRUEFALSE,而不是字符串。如果您要在表格上方查找标题,可以使用 title 选项。

    这是你的例子:

    library(shiny)
    library(data.table)
    library(DT)
    
    tabledata <- data.table(a=1:4, b= 5:8)
    ui <- fluidPage(
            DT::dataTableOutput("currenttable")
    )
    server <-  function(input,output, session){
            output$currenttable <- renderDT({tabledata},
                                            rownames = FALSE, 
                                            extensions = 'Buttons', 
                                            options = list(dom = 'Bfrtip',
                                                           pageLength = nrow(tabledata),
                                                           buttons = list(
                                                                   list(extend = 'copy'),
                                                                   list(extend = 'pdf',
                                                                        filename = 'CurrentTable',
                                                                        title = "My Title",
                                                                        header = FALSE)
                                                           )
                                                           )
                                            )
    }
    
    shinyApp(ui, server)
    

    【讨论】:

      猜你喜欢
      • 2018-03-13
      • 2017-05-15
      • 1970-01-01
      • 2016-11-06
      • 1970-01-01
      • 1970-01-01
      • 2019-03-12
      • 1970-01-01
      • 2017-04-07
      相关资源
      最近更新 更多