Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R datatable: Hide search box for individual columns

Tags:

r

dt

shiny

I would like to enable searching by columns but disable it for particular columns.

Here is almost what I need https://rstudio.github.io/DT/009-searchable.html but I would like to hide the unused boxes.

Any way to do that?

like image 738
Pekka Avatar asked Nov 19 '15 06:11

Pekka


People also ask

How do I remove a search from a DataTable in R?

By default DT::datatable has dom = 'lftipr' , simply drop the 'f' which is for the filter ("search" button). Save this answer.

How do you filter data in a DataTable?

With the DataTable. Select() method, you can directly assign filter rows to an array or data table using this expression. Create a type variable, either DataTable or DataRow [], that is an array of Data Rows. By default, this method returns the array of data rows but you can convert it at any time to a Data Table.


1 Answers

You use CSS with a selector on the disabled inputs of type search to hide them.

Here's an example in a shiny app:

library(shiny)

shinyApp(

  ui = fluidPage(tags$head(tags$style(
    HTML("input[type='search']:disabled {visibility:hidden}")
  )),
  DT::dataTableOutput('tbl')),

  server = function(input, output) {
    iris2 = head(iris, 10)
    output$tbl = DT::renderDataTable(datatable(
      iris2,
      filter = 'top',
      options = list(columnDefs = list(list(
        targets = c(1, 3), searchable = FALSE
      )),
      pageLength = 5)
    ))
  }
)
like image 101
NicE Avatar answered Oct 02 '22 23:10

NicE