【问题标题】:R Shiny DT - enter search text programmaticallyR Shiny DT - 以编程方式输入搜索文本
【发布时间】:2018-11-01 20:52:44
【问题描述】:

是否可以通过代码输入搜索框文字?要求的行为是:用户在textInput('search2', "Search 2") 中输入文本,该文本在 DT 搜索框中复制,并在 DT 上执行搜索。

library(shiny)
library(DT)
shinyApp(
  ui = fluidPage(
    textInput('search2', "Search 2"),
    DTOutput('dt')
  ),
  server = function(input, output, session) {
    output$dt = renderDT(iris)
  })

我不想以另一种方式过滤 DT 数据(我目前正在这样做) - 特别是我希望使用 DT 的搜索框功能。

【问题讨论】:

    标签: r shiny dt


    【解决方案1】:

    您可以为您的 DT 创建一个datatableProxy,它允许操作现有的 DT 实例。使用函数updateSearch

    library(shiny)
    library(DT)    
    
    shinyApp(
      ui = fluidPage(
        textInput('search2', "Search 2"),
        DTOutput('dt')
      ),
      server = function(input, output, session) {
    
        DTproxy <- dataTableProxy("dt")
        output$dt = renderDT(iris)
    
        observeEvent(input$search2, {
          updateSearch(DTproxy, keywords = list(global = input$search2, columns = NULL))
        })
    
      })
    

    【讨论】:

      【解决方案2】:

      除了@shosaco 他的回答:

      通过添加以下 CSS 隐藏 DataTable 的搜索框:

      .dataTables_filter {
      visibility: hidden;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-12-19
        • 2019-04-20
        • 2021-04-17
        • 2021-12-13
        • 1970-01-01
        • 1970-01-01
        • 2020-10-28
        • 1970-01-01
        相关资源
        最近更新 更多