suppress records per page dropdown and search box in data tables

7,211 views
Skip to first unread message

Dan

unread,
Nov 20, 2013, 5:56:24 PM11/20/13
to shiny-...@googlegroups.com
Hi, I'm following the data tables example on the R shiny tutorial.

http://rstudio.github.io/shiny/tutorial/#datatables

Here, it shows options to control the number of records per page, e.g. 5,10,50 or 25, 50, 100, etc.

Is there a way to suppress this dropdown completely and show all the records?  Also, is there a way to remove the search box as well?


Killian Mullan

unread,
Nov 21, 2013, 5:46:53 AM11/21/13
to shiny-...@googlegroups.com

Hi Dan,

I spent a bit of time in the jQuery datatables documentation (datatables.net/) and I managed to put this together.

First, to suppress the global search box I added the following CSS in my mainPanel() in the ui.R script:

tags$head(
tags$style(type="text/css", ".dataTables_filter {display: none;    }"
)

Then, I added "bLengthChange=F" as an option in the renderDataTable function in the server.R script.

There may be better ways to do this.

I'm still trying to figure out how to remove the column filtering at the bottom of the table. I can see how this would be useful with large tables, but with small tables (where you see everything in one page) it is less important and takes up too much visual space.

Hope this helps.

K.

Udrescu Tudor

unread,
Nov 21, 2013, 7:42:49 AM11/21/13
to shiny-...@googlegroups.com
Hi, 

I also wanted to get rid of the column filter elements at the bottom and your answer gave me an idea. Below is a minimal example how to obtain a stripped down DataTable with some custom column sizes. 

library(shiny)

runApp(
  list(
    server=function(input, output, session) {
      
      output$customtable = renderDataTable({
        mtcars},  
        options=list(iDisplayLength=5,                    # initial number of records
                     aLengthMenu=c(5,10),                  # records/page options
                     bLengthChange=0,                       # show/hide records per page dropdown
                     bFilter=0,                                    # global search box on/off
                     bInfo=0,                                      # information on/off (how many records filtered, etc)
                     bAutoWidth=0,                            # automatic column width calculation, disable if passing column width via aoColumnDefs
                     aoColumnDefs = list(list(sWidth="300px", aTargets=c(list(0),list(1))))    # custom column size                       
                    )
      )
    },
    
    ui=basicPage(
      tagList(
        singleton(
          tags$head(
            tags$style(type="text/css", "tfoot {display:none;}")
            )
          )
        ),
       dataTableOutput('customtable')
    )
  )
)
 

Regards,

T.

Stéphane Laurent

unread,
Nov 21, 2013, 8:14:01 AM11/21/13
to shiny-...@googlegroups.com
Thank you, very helpful. 

I'm using the following list of options, but I don't see what is the role of the second number in aLengthMenu ? :
    options=list(
      iDisplayLength=15,  # initial number of records
      aLengthMenu=c(15,3),  # records/page options
      bLengthChange=0,  # show/hide records per page dropdown
      bFilter=1,  # global search box on/off
      bInfo=1,   # information on/off (how many records filtered, etc)
      bAutoWidth=1  # automatic column width calculation, disable if passing column width via aoColumnDefs
      #aoColumnDefs = list(list(sWidth="300px", aTargets=c(list(0),list(1))))    # custom column size                       
    )

In addition, I don't understand the difference between the two red numbers ?

Udrescu Tudor

unread,
Nov 21, 2013, 1:40:29 PM11/21/13
to shiny-...@googlegroups.com
Hello, 

the iDisplayLength option represents the initial number of rows to display when using pagination, while aLengthMenu just allows you to select the options which will be presented to the user in the dropdown menu. In my example, I just changed the defaults from DataTables, i.e., [10, 25, 50, 100] to [5,10]. 

I am not sure if all the parameters available in DataTables can be used with the Shiny widget just yet, but most of the options listed under http://datatables.net/usage/features or http://datatables.net/usage/columns should work. 

Cheers,

Tudor

Dan

unread,
Nov 21, 2013, 2:07:34 PM11/21/13
to shiny-...@googlegroups.com
Thanks to all who posted.  Very helpful!.

Killian Mullan

unread,
Nov 22, 2013, 5:43:15 AM11/22/13
to shiny-...@googlegroups.com
Cool. Thanks that worked very nicely. K.
Reply all
Reply to author
Forward
0 new messages