[英]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.