Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Shiny: How to add pagination in DT::renderDataTable

Tags:

r

dt

shiny

I am trying to add pagination, search box and selector in my R Shiny app, but it doesn't work for now (I tried paging = TRUE and searching = TRUE, in options as you can see bellow but it doesn't work). Do you have any idea of what I should add?

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"
                           ))

I have added a screenshot of table I have now, and the expected table. Thanks for your help![enter image description here]1

like image 861
Remi Avatar asked Nov 24 '25 09:11

Remi


1 Answers

You can modify the dom parameter, for example as follows:

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')
  ))

enter image description here


To add page length, also add l to the string. Hope this helps!

like image 156
Florian Avatar answered Nov 26 '25 22:11

Florian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!