【问题标题】:shiny datatable in landscape orientation横向的闪亮数据表
【发布时间】:2023-03-20 08:20:01
【问题描述】:

我在闪亮中的代码如下

DT::renderDataTable({ 
  df()
  , rownames=FALSE
  ,extensions = c('Responsive', 'Buttons')
  , options = list(
    # dom = 'C<"clear">T<"clear">lfrtip'
    # , tableTools=list(sSwfPath = copySWF('www'))
    dom = 'Bfrtip'
    , buttons = c('pageLength'
                  , 'colvis'
                  , 'pdf')
    , orientation ='landscape'
    , lengthMenu = list(c(6, 12, 18, -1), c('6', '12', '18', 'All'))
    , pageLength = 12
    )
  )
}
})

我想横向下载 pdf。我该怎么做。

根据以下链接:https://datatables.net/reference/button/pdf,我们可以将方向作为横向传递。但是,我做不到。

我尝试了以下方法:

DT::renderDataTable({ 
  df()
  , rownames=FALSE
  ,extensions = c('Responsive', 'Buttons')
  , options = list(
    # dom = 'C<"clear">T<"clear">lfrtip'
    # , tableTools=list(sSwfPath = copySWF('www'))
    dom = 'Bfrtip'
    , buttons = c('pageLength'
                  , 'colvis'
                  , list(extend: 'pdf', orientation='landscape')
    , orientation ='landscape'
    , lengthMenu = list(c(6, 12, 18, -1), c('6', '12', '18', 'All'))
    , pageLength = 12
    )
  )
}
})

【问题讨论】:

    标签: r datatables shiny


    【解决方案1】:

    这对我有用。由于您没有提供数据,因此我使用了 iris 数据集。不是 pdf 是横向的,但表格没有使用所有可用空间,但行为与 datatables example 中的相同。它在 RStudio 中不起作用,但在浏览器 (Firefox 49.0) 中起作用

    这是代码:

        library(shiny)
        library(DT)
    
        shinyApp(
                ui = fluidPage(DT::dataTableOutput('tbl')),
                server = function(input, output) {
                        output$tbl = DT::renderDataTable(
                                datatable(
                                        iris,
                                        rownames = FALSE,
                                        extensions = c('Responsive', 'Buttons'), options = list(
                                                pageLength = 12,
                                                orientation ='landscape',
                                                lengthMenu = list(c(6, 12, 18, -1), c('6', '12', '18', 'All')),
                                                dom = 'Bfrtip',
                                                buttons = 
                                                        list('pageLength', 'colvis', list(
                                                                extend = 'pdf',
                                                                pageSize = 'A4',
                                                                orientation = 'landscape',
                                                                filename = 'tt'
    
    
                                                        ))
    
                                        ))
                        )
                }
        )
    

    【讨论】:

    • 我很抱歉,但我不得不评论这个惊人的优秀回应。谢谢好心的先生。
    猜你喜欢
    • 2017-11-29
    • 2019-02-18
    • 2021-02-13
    • 1970-01-01
    • 1970-01-01
    • 2018-08-03
    • 2019-07-04
    • 2018-02-01
    • 2017-06-04
    相关资源
    最近更新 更多