使用 bslib 时覆盖 DT 默认选择颜色

Override DT default selection color when using bslib

这个问题与R DT override default selection color, parts of the code is used, but on top of that i want to use https://github.com/rstudio/bslib关于样式的问题非常相似。

我想在 DT-table 中选择一行时覆盖默认颜色,但失败了几个小时。

这是一些要使用的代码

library(shiny)
library(DT)

library(bslib)

color_sel <-"#7cfc00" 

ui <- fluidPage(
  theme = bslib::bs_theme(version = 4,
                          bootswatch = "flatly",
                        #  bootswatch = NULL,
                          primary = '#00488E',
                          secondary = '#4AB9FA',
                          success = "#4AB9FA",
                          info = "#4AB9FA"
  ) %>% 
  bs_add_variables(
    "body-bg" = "#EEEEEE",
    "font-family-base" = "monospace",
    "table_active_bg" = color_sel
  )
  ,
#  tags$style(HTML(paste0("table.dataTable tbody tr.selected td, table.dataTable td.selected{background-color: ", color_sel," !important;}"))),
  fluidRow(dataTableOutput("tbl"))
)
server <- function(input, output){
  output$tbl <- renderDataTable({
    datatable(mtcars)
  })
  
}

app <- shinyApp(ui = ui, server= server)
runApp(app)

如您所见,我也尝试了两个地方用漂亮的绿色覆盖标准蓝色,但它不起作用。 bs_add_variables() 正在运行,由 body-bg 和 font-family-base 检查。怎么了?

实际上,更多的搜索导致了这个解决方案。将 CSS 的这一点添加到您的应用中:

table.dataTable tbody tr.active td {
    background: pink !important;
}