【问题标题】:Override renderDT datatable style覆盖 renderDT 数据表样式
【发布时间】: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 参数,则数据表的样式完全符合引导主题,而没有自定义的粉色选定行样式。

如何将引导主题应用到数据表并覆盖所选行的样式?

【问题讨论】:

    标签: css r shiny


    【解决方案1】:

    shinythemes 覆盖html 代码中的css 样式和类。因此,您需要在应用自定义 css 时考虑新的类名。以下指令可以解决问题(而不是原来的tags$style(HTML('table.dataTable tr.selected td,...))):

    tags$style(HTML('table.dataTable tr.active td {background-color: pink !important;}'))
    

    【讨论】:

    • 这正是我所需要的。我把它放在这里,一切正常。 ``` ui
    猜你喜欢
    • 2013-01-12
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-10
    • 2013-07-08
    相关资源
    最近更新 更多