Pekka Pekka - 3 years ago 91
R Question

R datatable: Hide search box for individual columns

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?

Answer Source

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)
    ))
  }
)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download