【问题标题】:Highlight rows in Datatable on matching search criteria根据匹配的搜索条件突出显示 Datatable 中的行
【发布时间】:2017-11-13 16:49:49
【问题描述】:

有没有办法根据 R Shiny 中数据表中的搜索条件突出显示一行?

在使用数据表时,我们会在顶部找到相应过滤行的搜索栏。我想突出显示匹配搜索条件的行中的部分。

谢谢。

【问题讨论】:

标签: r shiny dt


【解决方案1】:

如何在 R 中突出显示数据表。闪亮的实现应该是直截了当的。

library(DT)
mtcars2 = head(mtcars[, 1:5], 20)
mtcars2$model = rownames(mtcars2)
rownames(mtcars2) = NULL
options(DT.options = list(pageLength = 5))
# global search
datatable(mtcars2, options = list(searchHighlight = TRUE, search = list(search = 'da')))

请看这里:R Studio DT Explanation

编辑:

闪亮的小例子

server.R:

shinyServer(function(input, output) {
  output$testme <- renderDataTable({

    mtcars2 = head(mtcars[, 1:5], 20)
    mtcars2$model = rownames(mtcars2)
    rownames(mtcars2) = NULL
    options(DT.options = list(pageLength = 5))
    # global search
    datatable(mtcars2, options = list(searchHighlight = TRUE, search = 
list(search = 'da')))
  })

})

ui.R:

library(shiny)
library(DT)
shinyUI(fluidPage(
  DT::dataTableOutput(outputId = "testme")
  )
)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-22
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多