这是我正在使用的formattable对象的最小示例:
library(formattable)
formattable(mtcars,
align = "c",
list(~ formatter("span",
style = x ~ formattable::style(display = "block",
"border-radius" = "2px",
"padding" = "5px",
"text-align" = "center"))))
如何修改它以粗体显示行名?
最佳答案
这个怎么样?
我不得不做一个“肮脏的把戏”:我将行名添加为一列,然后将其命名为“”,所以它没有显示出来……但是我认为这可以解决问题:
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")))
)