在 DT Shiny R 中更改滤镜标签的颜色

Change color of filter labels in DT Shiny R

我在 shiny 中有一个 DT,我在其中为每个列名称添加了一个过滤器。我还添加了自定义 css 来更改 table 的颜色。但是,当我去过滤一列时,滑块上的值与背景融为一体。我想将值设置为“黑色”。 见附件照片。

#ui body
body(
 tags$style(HTML('table.dataTable tr:nth-child(even) {background-color: #1b1b21 !important;color: #e8e8e8 !important;}}')),
        tags$style(HTML('table.dataTable tr:nth-child(odd) {background-color: #242932 !important; color: #e8e8e8 !important;}')),
        tags$style(HTML('table.dataTable th {background-color: #1b1b21 !important;}')),
        tags$style(HTML(".dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing,.dataTables_wrapper .dataTables_paginate .paginate_button, .dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
            color: #5daa45 !important;
        }"))

DTOutput("mytable")
)

可以像改变其他颜色一样完成,这里是 CSS 选择器:

tags$style(HTML('table.dataTable thead tr td {color: black !important;}')),

可重现的例子:

library(shiny)
library(DT)

ui <- fluidPage(
  tags$style(HTML('table.dataTable tr:nth-child(even) {background-color: #1b1b21 !important;color: #e8e8e8 !important;}}')),
  tags$style(HTML('table.dataTable tr:nth-child(odd) {background-color: #242932 !important; color: #e8e8e8 !important;}')),
  tags$style(HTML('table.dataTable thead tr td {color: black !important;}')),
  tags$style(HTML('table.dataTable th {background-color: #1b1b21 !important;}')),
  tags$style(HTML(".dataTables_wrapper .dataTables_length, .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_processing,.dataTables_wrapper .dataTables_paginate .paginate_button, .dataTables_wrapper .dataTables_paginate .paginate_button.disabled {
            color: #5daa45 !important;
        }")),
    dataTableOutput("mytable")
)

server <- function(input, output, session) {
  
  output$mytable <- renderDataTable({
    datatable(cars,filter = "top")
  })
}

shinyApp(ui, server)