【发布时间】:2020-03-31 11:57:28
【问题描述】:
与this question 类似,可以在DTOutput() 函数之前使用tags$style(HTML(...)) 更改数据表输出中选定行的颜色。例如,
library(shiny)
library(DT)
library(shinythemes)
ui <- fluidPage(theme = shinytheme("cyborg"),
tags$style(HTML('table.dataTable tr.selected td, table.dataTable td.selected {background-color: pink !important;}')),
mainPanel(DT::dataTableOutput('mytable'))
)
server <- function(input, output,session) {
output$mytable = DT::renderDataTable(
datatable(mtcars,
#style = "bootstrap" # Uncomment to see how the custom css above is overriden
)
)
}
runApp(list(ui = ui, server = server))
上面的代码呈现了一个格式清晰的白色表格,在黑暗的 Cyborg 引导主题中显得格格不入。但是,它确实应用了自定义 css,这意味着选定的行变为粉红色。相比之下,如果您取消注释 datatable 中的 style 参数,则数据表的样式完全符合引导主题,而没有自定义的粉色选定行样式。
如何将引导主题应用到数据表并覆盖所选行的样式?
【问题讨论】: