问题
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?
回答1:
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)
))
}
)
来源:https://stackoverflow.com/questions/33797072/r-datatable-hide-search-box-for-individual-columns