如何在Shiny DataTables列中进行精确搜索

问题描述 投票:0回答:1

我有以下自给自足的闪亮脚本:

mydf <- data.frame(commonality=c("common","uncommon","common","uncommon","common"),value=c(1,2,3,4,5))

library(shiny)
shinyApp(
  ui = fluidPage(DT::dataTableOutput('tbl')),
  server = function(input, output) {
    output$tbl = DT::renderDataTable(
      mydf, options = list(lengthChange = FALSE)
    )
  }
)

产生这个:

enter image description here

我想做的是进行精确搜索。例如,当我输入

common
时, 值
uncommon
不应出现。我怎样才能做到这一点?

r shiny dt
1个回答
1
投票

您可以使用DT包的过滤器:

 library(shiny) 
    shinyApp( ui = fluidPage(DT::dataTableOutput('tbl')), 
    server = function(input, output) { 
    output$tbl = DT::renderDataTable( mydf,filter = 'top', options = list(lengthChange = T, dom = 'tip') )
      })

结果如下所示:enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.