Css 覆盖renderDT数据表样式

Css 覆盖renderDT数据表样式,css,r,shiny,Css,R,Shiny,与之类似,可以使用标记$styleHTML更改数据表输出中选定行的颜色。。。在DTOutput函数之前。例如: 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

与之类似,可以使用标记$styleHTML更改数据表输出中选定行的颜色。。。在DTOutput函数之前。例如:

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))
上面的代码呈现了一个格式简单的白色表格,在黑暗的电子人引导主题中看起来不合适。但是,它确实应用了自定义css,这意味着选定的行变成粉红色。相反,如果取消对datatable中的style参数的注释,datatable的样式将完全符合引导主题,而不使用自定义的粉色选定行样式

如何将引导主题应用于datatable并覆盖选定行的样式?

包shinythemes覆盖html代码中的css样式和类。因此,在应用自定义css时,需要考虑新的类名。以下指令执行此操作,而不是原始标记$styleHTML'table.dataTable tr.selected td,…:


这正是我需要的。我把它放在这里,一切正常用户界面
tags$style(HTML('table.dataTable tr.active td {background-color: pink !important;}'))