R Shiny:如何在 DT::renderDataTable 中添加分页

Rem*_*emi 3 r shiny dt

我正在尝试在我的 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"
                           ))
Run Code Online (Sandbox Code Playgroud)

我添加了我现在拥有的表格的屏幕截图以及预期的表格。谢谢你的帮助![在此处输入图片说明] 1

Flo*_*ian 5

您可以修改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')
  ))
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明


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