R shiny datatable pagination and show all rows as options

I have a datatable in a shiny application where I am doing pagination to show only 15 rows. But can I add an option where the user can see 15 rows at a time using pagination or a show all button which will show all the records with a scroll bar may be.

library(shiny)
library(DT)
ui <- fluidPage(
  dataTableOutput('myTable') 
)

server <- function(input, output, session) {
  output$myTable <- renderDataTable(mtcars, 
                                    options = list(pageLength = 15, info = FALSE)
  )
}

shinyApp(ui, server)

Hello,

A quick way to display a "show all" option with DT :

renderDataTable(mtcars, 
          options = list(pageLength = 15, info = FALSE,
                      lengthMenu = list(c(15, -1), c("15", "All")) ) )

HTH ! :slight_smile:

4 Likes

Thank you. There is another way if you want to add buttons.

 output$ex2 <- DT::renderDataTable(
      DT::datatable(
        iris, 
        extensions = 'Buttons',
        options = list(
          dom = 'Bfrtip',
          lengthMenu = list(c(5, 15, -1), c('5', '15', 'All')),
          pageLength = 15,
          buttons = list(
            list(
              extend = "collection",
              text = 'Show All',
              action = DT::JS("function ( e, dt, node, config ) {
                                    dt.page.len(-1);
                                    dt.ajax.reload();
                                }")
            )
          )
        )
      )
    )

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.