首页 > 解决方案 > R Shiny:如何在 DT::renderDataTable 中添加分页

问题描述

我正在尝试在我的 R Shiny 应用程序中添加分页、搜索框和选择器,但它现在不起作用(我尝试了分页 = TRUE 和搜索 = TRUE,在选项中你可以在下面看到但它不起作用) . 你知道我应该添加什么吗?

output$mytable1  <- DT::renderDataTable(
                            DT::datatable(
                                { plots.dfs()[[1]] },
                                caption = htmltools::tags$caption(
                                    style = 'caption-side: bottom; text-align: center;',
                                    'Table 2: ', htmltools::em('This is a simple caption for the table.')
                                ),
                                extensions = 'Buttons',

                                options = list(
                                    paging = TRUE,
                                    searching = TRUE,
                                    fixedColumns = TRUE,
                                    autoWidth = TRUE,
                                    ordering = TRUE,
                                    dom = 'tB',
                                    buttons = c('copy', 'csv', 'excel')
                                ),

                                class = "display"
                           ))

我已经添加了我现在拥有的表格的屏幕截图以及预期的表格。感谢您的帮助![在此处输入图像描述] 1

标签: rshinydt

解决方案


可以修改dom参数,例如如下:

DT::datatable(
  { mtcars },
  caption = htmltools::tags$caption(
    style = 'caption-side: bottom; text-align: center;',
    'Table 2: ', htmltools::em('This is a simple caption for the table.')
  ),
  extensions = 'Buttons',

  options = list(
    fixedColumns = TRUE,
    autoWidth = TRUE,
    ordering = TRUE,
    dom = 'Bftsp',
    buttons = c('copy', 'csv', 'excel')
  ))

在此处输入图像描述


要添加页面长度,还要添加l到字符串。希望这可以帮助!


推荐阅读