Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 403
saheed Avatar asked Mar 30 '19 00:03

saheed


1 Answers

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

like image 157
LocoGris Avatar answered Nov 05 '22 05:11

LocoGris