Create a formatter function making HTML elements
HTML tag name. Uses
span by default.
functions to create attributes of HTML element from data colums.
The unnamed element will serve as the function to produce the inner text of the
element. If no unnamed element is provided,
identity function will be used
to preserve the string representation of the colum values. Function and formula are
accepted. See details for how different forms of formula will behave differently.
a function that transforms a column of data (usually an atomic vector) to formatted data represented in HTML and CSS.
This function creates a
formatter object which is essentially a
closure taking a value and optionally the dataset behind.
The formatter produces a character vector of HTML elements represented
as strings. The tag name of the elements are specified by
and its attributes are calculated with the given functions or formulas
... given the input vector and/or dataset in behind.
x ~ expr will behave like
~expr will be evaluated in different manner:
will be evaluated in the data frame with the enclosing environment being
the formula environment. If a column is formatted according to multiple
~expr should be used and the column names can directly
top10red <- formatter("span", style = x ~ ifelse(rank(-x) <= 10, "color:red", NA)) yesno <- function(x) ifelse(x, "yes", "no") formattable(mtcars, list(mpg = top10red, qsec = top10red, am = yesno)) # format one column by other two columns # make cyl red for records with both mpg and disp rank <= 20 f1 <- formatter("span", style = ~ ifelse(rank(-mpg) <= 20 & rank(-disp) <= 20, "color:red", NA)) formattable(mtcars, list(cyl = f1))