简体   繁体   English

DT::DataTables 中第一列的黑色背景和白色字体

[英]Black background with white font for first column in DT::DataTables

I have a shiny app with a DT::DataTable element in which the first column is a row header and the second column contains data.我有一个带有 DT::DataTable 元素的闪亮应用程序,其中第一列是行标题,第二列包含数据。 How can I change the color of the first column to be white text on a black background?如何将第一列的颜色更改为黑色背景上的白色文本? If found ways to change the column headers (section 4.3 here ), but I how do I get the same effect applied to the first column?如果找到更改列标题的方法(此处为第 4.3 节),但我如何将相同的效果应用于第一列?

Here's some example code showing a very simplified version of the table without the desired effect.下面是一些示例代码,显示了一个非常简化的表格版本,但没有预期的效果。 I'm certain that adding something to the options list in the renderDataTable function will solve it, but I don't know what to add.我确信在renderDataTable函数中的选项列表中添加一些东西会解决它,但我不知道添加什么。

library(shiny)
library(DT)

# Define UI for application that draws a histogram
ui <- fluidPage(
    fluidRow(
        column(3,
            DT::dataTableOutput(outputId = 'tbl')
        )
    )
)

# Define server logic required to draw a histogram
server <- function(input, output) {
    output$tbl<- DT::renderDataTable(
    rownames = FALSE, colnames = '', options = list(dom = 't'),
    {
        df <- data.frame(
            Label = c('Label1', 'Label2', 'Label3', 'Label4'),
            Data = c('Data1', 'Data2', 'Data3', 'Data4')
        )
        return(df)
    })
}

# Run the application 
shinyApp(ui = ui, server = server)
library(shiny)
library(DT)

CSS <- HTML(
  "td.firstcol {color: white; background-color: black}"
)

ui <- fluidPage(
  tags$head(
    tags$style(CSS)
  ),
  fluidRow(
    column(3,
           DTOutput(outputId = 'tbl')
    )
  )
)


server <- function(input, output) {
  output$tbl<- renderDT({
    datatable(
      data.frame(
        Label = c('Label1', 'Label2', 'Label3', 'Label4'),
        Data = c('Data1', 'Data2', 'Data3', 'Data4')
      ),
      rownames = FALSE, 
      colnames = "", 
      options = list(
        dom = 't',
        columnDefs = list(
          list(targets = 0, className = "firstcol")
        )
      )
    )
  })
}

# Run the application 
shinyApp(ui = ui, server = server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 R中的tesseract - 在黑色背景上读取白色字体 - tesseract in R - read white font on black background DT dataTable中的列总数有光泽 - Total of a column in DT dataTables in shiny 更改 R DataTables (DT) 中的字体大小 - changing font size in R DataTables (DT) 使用 Formattable 将表格背景颜色更改为黑色,将所有字体颜色更改为白色 - Changing table background color to black and all font color to white using Formattable DT数据表背景颜色为黑色,但仍具有悬停和选择颜色 - DT datatable background colour black, but still have hover and selection colours R:黑色背景上的白色绘图元素 - R: White plot elements on black background 更改DT包中的字体 - Changing font in DT package 当使用列级搜索时,DT :: datatables()生成的html表显示显示异常(缺少字符) - DT::datatables() generated html table shows display anomalies (missing characters) when column level search is used 在 Highcharter 中向黑白柱形图添加图案填充 - Adding a pattern fill to a black and white column graph in Highcharter 如何在不增加旋转 (90°) 列名的表的列宽的情况下冻结 DT 中的第一列? - How can I freeze the first column in DT without increasing the column width of a table with rotated (90°) column names?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM