簡體   English   中英

Shiny DT表中的多個關鍵字批量搜索

[英]Multiple keyword batch searching in Shiny DT tables

有誰知道是否可以在 R 的 DT 數據表中進行批量關鍵字搜索? 例如,在下面的代碼中,是否可以在搜索框中一次搜索 3 輛特定汽車? 理想情況下,我想一次在搜索框中粘貼“Mazda RX4”、“Merc 230”、“Fiat 128”,然后在下表中查看結果,而無需單獨搜索每個。

我從事生物信息學工作,我的同事希望在我們的交互式表格中搜索特定的蛋白質/基因列表等,而不必單獨粘貼每個表格。

示例代碼:


## 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 

示例 搜索表

對於批量搜索,添加| pipe 用於正則表達式識別它們的多個汽車名稱之間。

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”共享的汽車。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM