Search code examples
rshinydtflexdashboard

Can you change the R default table length when outputting with the DT package?


In R DT you can define the table control elements with code such as:

# only display the table, and nothing else
library(DT)
datatable(mtcars, options = list(dom = 't'))

The t above is a DOM. The DOM element l controls the length changing input control, basically how long your table will be. It looks like this.

show entries selection

This length changing input control defaults to a value of 10. How can I change this default value to 25, 100, perhaps even "All"?


Solution

  • You can change it to 3 by datatable(mtcars, options = list(dom = 't', pageLength = 3)).

    This will get you your desired results:

    datatable(mtcars, options = list(dom = 't',
      lengthMenu = list(c(25, 100, -1), c('25', '100', 'All')),
      pageLength = 25
    ))