Add text colour to a specific column name (header) in DT Shiny datatable -
i new dt in shiny , add text colour specific columns in table, can using formatstyle
per below example code chunk. however, add same text colour corresponding column name (header), there easy way this?
library(shiny) library(dt) ui = fluidpage(dt::datatableoutput('fdatatable')) server = function(input, output) { output$fdatatable = dt::renderdatatable({ dt::datatable(iris) %>% formatstyle(columns = 1, color = "red") %>% formatstyle(columns = 3, color = "blue") }) } app = list(ui = ui, server = server) runapp(app)
any appreciated.
you can adding css colnames
of table rendering (you need set escape
false
or html escaped).
here's example:
library(shiny) library(dt) ui = fluidpage(dt::datatableoutput('fdatatable')) server = function(input, output) { output$fdatatable = dt::renderdatatable({ iris_coloured <- iris colnames(iris_coloured)[c(1,3)] <- paste0('<span style="color:',c("red","blue"),'">',colnames(iris)[c(1,3)],'</span>') dt::datatable(iris_coloured,escape=f) %>% formatstyle(columns = 1, color = "red") %>% formatstyle(columns = 3, color = "blue") }) } app = list(ui = ui, server = server) runapp(app)
Comments
Post a Comment