The icon_sets() function conditionally adds an icon from the Font Awesome library (via shiny) to each cell of a column and assigns a color depending on their value in relation to other values in that particular column. Any number of icons and any number of colors can be used. The number of icons and colors determines how the values are shown from low values to high values. The icons can be positioned over, above, below, or to the right or left of the values. The size of the icon can be adjusted. Icons and icon colors can be provided via another reference column in the dataset which is useful when assigning icons/colors to particular occurrences. It should be placed within the cell argument in reactable::colDef.

## Usage

icon_sets(
data,
icons = c("circle"),
icon_set = NULL,
colors = c("#15607A", "#B0B0B0", "#FA8C00"),
opacity = 1,
icon_position = "right",
icon_ref = NULL,
icon_size = 16,
icon_color_ref = NULL,
number_fmt = NULL,
tooltip = FALSE,
animation = "1s ease"
)

## Arguments

data

Dataset containing at least one numeric column.

icons

A vector of three icons from the Font Awesome library (via shiny). Icons should be given in order from low values to high values. Default icons are circles.

icon_set

Apply a pre-selected set of icons to values. Options are "ski rating", "medals", and "batteries". Default is NULL.

colors

The color(s) to assign to the icons. Colors should be given in order from low values to high values. Default colors provided are blue-grey-orange: c("#15607A", "#B0B0B0", "#FA8C00"). Can use R's built-in colors or other color packages.

opacity

A value between 0 and 1 that adjusts the opacity in colors. A value of 0 is fully transparent, a value of 1 is fully opaque. Default is 1.

icon_position

Position of icon relative to numbers. Options are "left", "right", above", "below", or "over". Default is right.

icon_ref

Optionally assign icons from another column by providing the name of the column containing the icons in quotes. Only one icon can be provided per cell. Default is NULL.

icon_size

A value representing the size of the icon in px. Default is 16.

icon_color_ref

Optionally assign color to the icons from another column by providing the name of the column containing the icon colors in quotes. Only one color can be provided per cell. Default is NULL.

number_fmt

Optionally format numbers using formats from the scales package. Default is set to NULL.

tooltip

Logical: hover tooltip. Default is FALSE.

animation

Control the duration and timing function of the animation when sorting/updating values shown on a page. See [CSS transitions](https://developer.mozilla.org/en-US/docs/Web/CSS/transition) for available timing functions and examples. Animation can be turned off by setting to "none". Default is "1s ease".

## Value

a function that applies an icon to a column of numeric values.

## Examples

data <- MASS::Cars93[20:49, c("Make", "MPG.city", "MPG.highway")]

## By default, icon_sets() assigns blue circles to the lowest-third values,
## grey circles to the middle-third values,
## and orange to the top-third values
reactable(data,
defaultColDef = colDef(cell = icon_sets(data)))
#> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator ## Apply pre-set icon sets with icon_set: reactable(data, defaultColDef = colDef(cell = icon_sets(data, icon_set = 'ski rating'))) #> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator

## Assign custom colors
reactable(data,
defaultColDef = colDef(cell = icon_sets(data,
colors = c("tomato", "grey", "dodgerblue"))))
#> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator ## Assign icons from Font Awesome's icon library reactable(data, defaultColDef = colDef(cell = icon_sets(data, icons = c("arrow-down","minus","arrow-up")))) #> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator

## Use number_fmt to format numbers using the scales package
car_prices <- MASS::Cars93[20:49, c("Make", "Price")]

reactable(car_prices,
defaultColDef = colDef(cell = icon_sets(car_prices,
number_fmt = scales::dollar)))
#> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator ## Position icons relative to the numbers. Options are to the left, right, above, below, or over. reactable(car_prices, defaultColDef = colDef(cell = icon_sets(car_prices, icon_position = "above"))) #> Error in x$width %||% settings$fig.width * settings$dpi: non-numeric argument to binary operator