R datatable:隐藏各列的搜索框

Pek*_*kka 6 r shiny dt

我想启用按列搜索,但禁用特定列.

这几乎是我需要的 https://rstudio.github.io/DT/009-searchable.html, 但我想隐藏未使用的盒子.

有办法吗?

Nic*_*icE 8

您在类型的禁用输入上使用带有选择器的CSS search来隐藏它们.

这是一个闪亮的应用程序中的示例:

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)
    ))
  }
)
Run Code Online (Sandbox Code Playgroud)