我有一个关于在 shiny
中实现的包 DT
的简单问题。我想在 Shiny 的应用程序中使用可渲染数据中的顶部过滤器来过滤掉包含特定单词的行。我已经在 options
regexp=TRUE
中进行了设置,但我仍然无法使其工作
我正在使用这个正则表达式
^((?!intronic).)*$
我尝试转义这部分((?!intronic).)
但它也不起作用
编辑
这是我渲染表格的完整代码
DT::datatable(df,
rownames = FALSE,
selection = "none",
style = 'bootstrap',
class = 'compact display',
#class = 'compact cell-border stripe hover',
filter = list(position = 'top', clear = FALSE),
escape = FALSE,
extensions = c('Buttons'),
options = list(
stateSave = FALSE,
ordering = FALSE,
autoWidth = TRUE,
searchCols = default_search_columns,
search = list(regex = TRUE, caseInsensitive = TRUE),
columnDefs = list(
list(
className = 'dt-center',
targets = cols_to_all,
render = JS("function(data, type, row, meta) {",
"return type === 'display' && typeof data === 'string' && data.length > 14 ?",
"'<span title=\"' + data + '\">' + data.substr(0, 14) + '...</span>' : data;",
"}")
),
list(
visible = FALSE,
targets = cols_to_hide
)),
initComplete = JS(
"function(settings, json) {",
"$(this.api().table().header()).css({'font-size': '12px'});",
"}"),
#dom = 'Bfrtip',
sDom = '<"top">Blrt<"bottom">ip', # remove search general box and keep the top filters
#dom = 'BT<"clear">frti',
#dom = 'Bftir',
scroller = TRUE,
scrollX = TRUE,
#scrollY = "800px",
deferRender=TRUE,
buttons = list('colvis'),
#FixedHeader = TRUE,
pageLength = 25,
lengthMenu = list(c(25, 50, 100, -1), list('25', '50', '100', 'All'))#,
)
我已在列表中包含搜索
选项
编辑2
这是我的 daframe 的一个例子,真实的有超过 50,000 行和 160 列。但是,我有兴趣将过滤器应用于名为 Func.refGene
>dput(df)
structure(list(Chr = c("chr1", "chr1", "chr1", "chr1", "chr1",
"chr1", "chr1", "chr1", "chr1", "chr1", "chr1", "chr1", "chr1",
"chr1", "chr1"), Start = c(69511L, 876499L, 877831L, 878314L,
879676L, 879676L, 879687L, 879687L, 881627L, 887560L, 887801L,
888639L, 888659L, 889158L, 889159L), End = c(69511L, 876499L,
877831L, 878314L, 879676L, 879676L, 879687L, 879687L, 881627L,
887560L, 887801L, 888639L, 888659L, 889158L, 889159L), GATK.RefCount = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
"0"), GATK.AltCount = c("55", "60", "138", "184", "111", "111",
"110", "110", "103", "66", "138", "73", "50", "96", "96"), GATK.Filter = c("MQ_LT_40",
"PASS", "PASS", "PASS", "PASS", "PASS", "PASS", "PASS", "PASS",
"PASS", "PASS", "PASS", "PASS", "PASS", "PASS"), Func.refGene = c("exonic",
"intronic", "exonic", "exonic", "UTR3", "UTR3", "UTR3", "UTR3",
"exonic", "intronic", "exonic", "exonic", "exonic", "splicing;intronic",
"splicing;intronic"), Gene.refGene = c("OR4F5", "SAMD11", "SAMD11",
"SAMD11", "NOC2L", "SAMD11", "NOC2L", "SAMD11", "NOC2L", "NOC2L",
"NOC2L", "NOC2L", "NOC2L", "NOC2L", "NOC2L"), GeneDetail.refGene = c(".",
".", ".", ".", "NM_015658:c.*398C>T;NM_152486:c.*143G>A", "NM_015658:c.*398C>T;NM_152486:c.*143G>A",
"NM_015658:c.*387A>G;NM_152486:c.*154T>C", "NM_015658:c.*387A>G;NM_152486:c.*154T>C",
".", ".", ".", ".", ".", "NM_015658:exon8:c.888+4C>G", "NM_015658:exon8:c.888+3T>G"
)), row.names = c(NA, 15L), class = "data.frame")
最佳答案
您必须像这样设置regex
选项:
library(DT)
datatable(iris,
options = list(search = list(regex = TRUE)))
然后您可以检查 ^((?!(setosa)).)*$
是否正常工作。
关于r - 使用不包含字符串的正则表达式过滤 Shiny 的DT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57823610/