How to change appearance of table header row with R formattable package

I'm using the formattable package in R to produce a HTML table. I can use formatter to customise the look of data values in in my table eg font-size, color etc. But I can't work out how to alter the appearance of the table header row.I can alter the actual column names using col.names(), but haven't been able to change their appearance.

For example, in the table below how can I change the text color or background color in the header row (mpg, cyl, disp etc.)

Ultimately, I plan to use formattable::as.htmlwidget() and library(webshot) to grab an image file of the table, see Command for exporting/saving table made with Formattable package in R

Thanks

library(formattable)

formatRed <- formatter("span"
    , style = x ~ style(color = ifelse(x > 21 , "red", "black")))

formatSize <-  formatter("span"
    , style = x ~ style("font-size" = "8px"))

exTb <- formattable(head(mtcars, 5)
    , table.attr = "class='table table-striped'"
    , list(mpg = formatRed
        , wt = formatSize)
)

exTb

I've spent the past 3 days investigating this issue. Unfortunately, there aren't many examples using formattable available, so for those starting to use formattable it is a little tricky. However, I have found a solution (thanks to the help of some geniuses!) to changing the font of the header and rows (which you may be able to apply to your problem). The trick was to make a custom CSS file, which allows you to change various elements of the table. You could then link the formattable using the table.attr parameter to this CSS file, or use a CSS container. This is my question here How do you change the font family in a formattable in R?. Hopefully this will help!

链接地址: http://www.djcxy.com/p/30960.html

上一篇: R中的HDBSCAN可视化应用文本标签而不是数字

下一篇: 如何用R格式化包更改表格标题行的外观