Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

styleInterval

Conditional CSS styles


Description

A few helper functions for the formatStyle() function to calculate CSS styles for table cells based on the cell values. Under the hood, they just generate JavaScript and CSS code from the values specified in R.

Usage

styleInterval(cuts, values)

styleEqual(levels, values, default = NULL)

styleValue()

styleColorBar(data, color, angle = 90)

styleRow(rows, values, default = NULL)

Arguments

cuts

a vector of cut points (sorted increasingly)

values

a vector of CSS values

levels

a character vector of data values to be mapped (one-to-one) to CSS values

default

a string or NULL used as the the default CSS value for values other than levels. If NULL, the CSS value of non-matched cells will be left unchanged.

data

a numeric vector whose range will be used for scaling the table data from 0-100 before being represented as color bars. A vector of length 2 is acceptable here for specifying a range possibly wider or narrower than the range of the table data itself.

color

the color of the bars

angle

a number of degrees representing the direction to fill the gradient relative to a horizontal line and the gradient line, going counter-clockwise. For example, 90 fills right to left and -90 fills left to right.

rows

the Row Indexes (starting from 1) that applies the CSS style. It could be an integer vector or a list of integer vectors, whose length must be equal to the length of values.

Details

The function styleInterval() maps intervals to CSS values. Its argument values must be of length n + 1 where n = length(cuts). The right-closed interval (cuts[i - 1], cuts[i]] is mapped to values[i] for i = 2, 3, ..., n; values[1] is for the interval (-Inf, cuts[1]], and values[n + 1] is for (cuts[n], +Inf). You can think of the order of cuts and values using this diagram: -Inf -> values[1] -> cuts[1] -> values[2] -> cuts[2] -> ... -> values[n] -> cuts[n] -> values[n + 1] -> +Inf.

The function styleEqual() maps data values to CSS values in the one-to-one manner, i.e. values[i] is used when the table cell value is levels[i].

The function styleColorBar() can be used to draw background color bars behind table cells in a column, and the width of bars is proportional to the column values.

The function styleValue() uses the column value as the CSS values.

The function styleRow() applies the CSS values based on Row Indexes.


DT

A Wrapper of the JavaScript Library 'DataTables'

v0.18
GPL-3 | file LICENSE
Authors
Yihui Xie [aut, cre], Joe Cheng [aut], Xianying Tan [aut], JJ Allaire [ctb], Maximilian Girlich [ctb], Greg Freedman Ellis [ctb], Johannes Rauh [ctb], jQuery contributors [ctb, cph] (jQuery in htmlwidgets/lib), SpryMedia Limited [ctb, cph] (DataTables in htmlwidgets/lib), Brian Reavis [ctb, cph] (selectize.js in htmlwidgets/lib), Leon Gersen [ctb, cph] (noUiSlider in htmlwidgets/lib), Bartek Szopka [ctb, cph] (jquery.highlight.js in htmlwidgets/lib), RStudio, PBC [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.