saheed
saheed

Reputation: 394

Bold row names of a formattable object

Here's a minimal example of the formattable object I'm working with:

library(formattable)
formattable(mtcars, 
            align = "c",
            list(~ formatter("span",
                             style = x ~ formattable::style(display = "block",
                                                            "border-radius" = "2px",
                                                            "padding" = "5px",
                                                            "text-align" = "center"))))

How can I modify it to bold the row names?

Upvotes: 5

Views: 1860

Answers (1)

LocoGris
LocoGris

Reputation: 4480

How about this? I had to do a "dirty trick": I add row names as a column and then named it as " " so it is not shown... But i think it makes the trick:

library(formattable)
mtcars$model <- rownames(mtcars)
rownames(mtcars) <- c()
mtcars <-mtcars[,c(12,c(1:11))]
colnames(mtcars)[1] = " "
formattable(mtcars, 
            align = "c",
            list(~ formatter("span",
                             style = x ~ formattable::style(display = "block",
                                                            "border-radius" = "2px",
                                                            "padding" = "5px",
                                                            "text-align" = "center")),
                ` ` = formatter("span",style = ~ style(display = "block",
                                                         "border-radius" = "2px",
                                                         "padding" = "5px",
                                                          "font.weight" = "bold",  
                                                          "text-align" = "left")))
                 )

enter image description here

Upvotes: 4

Related Questions