在闪亮的DT表中进行多关键字批量搜索 [英] Multiple keyword batch searching in Shiny DT tables

查看:53
本文介绍了在闪亮的DT表中进行多关键字批量搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道在R中的DT数据表中是否可以进行批量关键字搜索吗?例如,在下面的代码中,是否可以在搜索框中一次 搜索3辆特定的汽车?理想情况下,我想立即在搜索框中粘贴马自达RX4","Merc 230",菲亚特128",然后在下表中查看结果,而不必分别进行搜索.

Does anyone know if it's possible to have a batch keyword search in a DT datatable in R? For example, in the below code, is it possible to search for say 3 specific cars at once in the search box? Ideally I would like to paste in the search box at once, "Mazda RX4", "Merc 230", "Fiat 128" and then see the results in the table below without having to search each one individually.

我从事生物信息学工作,我的同事希望在我们的交互式表格中搜索蛋白质/基因等的特定列表,而不必单独粘贴每个蛋白质/基因.

I work in bioinformatics and colleagues of mine would like to search our interactive tables with a specific list of proteins/genes etc without having to paste each one individually.

示例代码:


## example taken from https://rstudio.github.io/DT/007-search.html
library(DT)
mtcars2 = mtcars[, c(1:5, 9)]
mtcars2$am = factor(mtcars$am, c(0, 1), c('automatic', 'manual'))
# search for Ma or Me
dt <- datatable(
  mtcars2, colnames = c('model' = 1),
  filter = list(position = 'top', clear = FALSE),
  options = list(
    search = list(regex = TRUE, caseInsensitive = TRUE),
    pageLength = 5
  )
)




## simple Shiny app with datatable
ui <- fluidPage(
  fluidRow(
    DT::dataTableOutput("table")
  )
)

server <- function(input, output) {
  output$table <- DT::renderDataTable(dt)
}

shinyApp(ui = ui, server = server)

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8

attached base packages:
[1] stats4    parallel  stats     graphics  grDevices utils     datasets  methods  
[9] base     

other attached packages:
 [1] ggplot2_3.3.0        DT_0.13              rsconnect_0.8.16     shinythemes_1.1.2   
 [5] dplyr_0.8.5          shiny_1.4.0.2        BiocParallel_1.20.1  MLInterfaces_1.66.5 
 [9] cluster_2.1.0        annotate_1.64.0      XML_3.99-0.3         AnnotationDbi_1.48.0
[13] IRanges_2.20.2       MSnbase_2.12.0       ProtGenerics_1.18.0  S4Vectors_0.24.4    
[17] mzR_2.20.0           Rcpp_1.0.4.6         Biobase_2.46.0       BiocGenerics_0.32.0 

推荐答案

对于批量搜索,在多个汽车名称之间添加 | 管道,以使正则表达式能够识别它们.

for Batch Search, add a | pipe between the multiple car names for regex to recognise them.

mtcars2 = mtcars[, c(1:5, 9)]
mtcars2$am = factor(mtcars$am, c(0, 1), c('automatic', 'manual'))
# search for Ma or Me
datatable(
  mtcars2, colnames = c('model' = 1),
  filter = list(position = 'top', clear = FALSE),
  options = list(
    search = list(regex = TRUE, caseInsensitive = FALSE, search = 'Maz|Hor'),
    pageLength = 5
  )
)

上面的代码将显示所有带有'Maz'或'Hor'的汽车.

The above code will show all cars sharting with either 'Maz' or 'Hor'.

这篇关于在闪亮的DT表中进行多关键字批量搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆