Skip to content Skip to sidebar Skip to footer

Change Header Style Formattable R

I'm trying to use formattable with some values for species, thus, it's very important for column names to be italic; I've tried with the formatter() function, but it only acts on t

Solution 1:

I don't know the formattable package, but the make_italic object that you create is a function that adds italics tags to character objects. You can use that on the column names directly. Because the names get changed you can no longer use them in your formattable function to format the columns, however you can format those column in the data.frame before changing the column names the same way. A bit hackish, but works.

library(formattable)
data(mtcars)
mtcars_tab        <- mtcars 
make_italic       <- formatter("span", style =  "font-style:italic")
mtcars_tab$mpg    <- make_italic(mtcars_tab$mpg)
mtcars_tab$qsec   <- make_italic(mtcars_tab$qsec)
names(mtcars_tab) <- make_italic(names(mtcars_tab))
formattable(mtcars_tab)

Post a Comment for "Change Header Style Formattable R"