Search code examples
rshinyformattable

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?


Solution

  • 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