This function is a preprocessing step before applying the htmlTable() function.
You use this to style your tables with HTML cascading style sheet features.
addHtmlTableStyle(
x,
align = NULL,
align.header = NULL,
align.cgroup = NULL,
css.rgroup = NULL,
css.rgroup.sep = NULL,
css.tspanner = NULL,
css.tspanner.sep = NULL,
css.total = NULL,
css.cell = NULL,
css.cgroup = NULL,
css.header = NULL,
css.header.border_bottom = NULL,
css.class = NULL,
css.table = NULL,
pos.rowlabel = NULL,
pos.caption = NULL,
col.rgroup = NULL,
col.columns = NULL,
padding.rgroup = NULL,
padding.tspanner = NULL,
spacer.celltype = NULL,
spacer.css.cgroup.bottom.border = NULL,
spacer.css = NULL,
spacer.content = NULL
)appendHtmlTableStyle(
x,
align = NULL,
align.header = NULL,
align.cgroup = NULL,
css.rgroup = NULL,
css.rgroup.sep = NULL,
css.tspanner = NULL,
css.tspanner.sep = NULL,
css.total = NULL,
css.cell = NULL,
css.cgroup = NULL,
css.header = NULL,
css.header.border_bottom = NULL,
css.class = NULL,
css.table = NULL,
pos.rowlabel = NULL,
pos.caption = NULL,
col.rgroup = NULL,
col.columns = NULL,
padding.rgroup = NULL,
padding.tspanner = NULL,
spacer.celltype = NULL,
spacer.css.cgroup.bottom.border = NULL,
spacer.css = NULL,
spacer.content = NULL
)
x with the style added as an attribute that the htmlTable then can use for formatting.
The css.cell parameter allows you to add any possible CSS style
to your table cells. css.cell can be either a vector or a matrix.
If css.cell is a vector, it's assumed that the styles should be repeated
throughout the rows (that is, each element in css.cell specifies the style
for a whole column of 'x').
In the case of css.cell being a matrix of the same size of the x argument,
each element of x gets the style from the corresponding element in css.cell. Additionally,
the number of rows of css.cell can be nrow(x) + 1 so the first row of of css.cell
specifies the style for the header of x; also the number of columns of css.cell
can be ncol(x) + 1 to include the specification of style for row names of x.
Note that the text-align CSS field in the css.cell argument will be overriden
by the align argument.
Excel has a specific css-style, mso-number-format that can be used for improving the
copy-paste functionality. E.g. the style could be written as: css_matrix <- matrix( data = "mso-number-format:\"\\@\"", nrow = nrow(df), ncol = ncol(df))
The function stores the current theme (see setHtmlTableTheme()) + custom styles
to the provided object as an base::attributes(). It is stored under the element
htmlTable.style in the form of a list object.
Other htmlTableStyle:
hasHtmlTableStyle()
# NOT RUN {
library(magrittr)
matrix(1:4, ncol = 2) %>%
addHtmlTableStyle(align = "c", css.cell = "background-color: orange;") %>%
htmlTable(caption = "A simple style example")
# }
Run the code above in your browser using DataLab