【发布时间】:2017-11-13 16:49:49
【问题描述】:
有没有办法根据 R Shiny 中数据表中的搜索条件突出显示一行?
在使用数据表时,我们会在顶部找到相应过滤行的搜索栏。我想突出显示匹配搜索条件的行中的部分。
谢谢。
【问题讨论】:
-
欢迎来到 StackOverflow!请阅读有关how to ask a good question 的信息以及如何提供reproducible example。这将使其他人更容易帮助您。
有没有办法根据 R Shiny 中数据表中的搜索条件突出显示一行?
在使用数据表时,我们会在顶部找到相应过滤行的搜索栏。我想突出显示匹配搜索条件的行中的部分。
谢谢。
【问题讨论】:
如何在 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')))
编辑:
闪亮的小例子
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")
)
)
【讨论】: