Nico
Nico

Reputation: 89

Changing table background color to black and all font color to white using Formattable

I am trying to change the background color of my entire table to black and all font colors to white using the Formattable Package in R. I understand you can use "span" but that only applies to columns (correct me if I'm wrong). Please feel free to share your thoughts or recommendations!

This is what I have so far. As you can see I used the "span" but it only applies to columns, but I would like to apply the color change to the entire table as a whole completely (NOT just every column):

color_change<-formatter("span", style = ~ style(color = "white",background-color="black")

widget_formattable = formattable(Table_Output,align = c("l", rep("r", NCOL(Table_Output) - 1)),list(Activity=color_change))

The end result should display the entire table as black background color with white font. Thanks in advance!

Upvotes: 1

Views: 759

Answers (2)

tamtam
tamtam

Reputation: 3671

You can define global table styles in the table.attr argument.

iris_sub <- iris[1:5,]

formattable(iris_sub,   
            table.attr = 'style="color: white; background-color: black";')

enter image description here

Upvotes: 2

pascal
pascal

Reputation: 1085

Actually, I don't think formattable can do that. Correct me if I'm wrong folks. I suggest you have a look at flextable. See following code and output:

set_flextable_defaults(background.color = "black", font.color = "white")
ft <- flextable(mtcars)

enter image description here

https://ardata-fr.github.io/flextable-book/

Upvotes: 1

Related Questions