cell_fill: Helper for defining custom fills for table cells

View source: R/helpers.R

cell_fillR Documentation

Helper for defining custom fills for table cells

Description

cell_fill() is to be used with tab_style(), which itself allows for the setting of custom styles to one or more cells. Specifically, the call to cell_fill() should be bound to the styles argument of tab_style().

Usage

cell_fill(color = "#D3D3D3", alpha = NULL)

Arguments

color

Cell fill color

⁠scalar<character>⁠ // default: "#D3D3D3"

If nothing is provided for color then "#D3D3D3" (light gray) will be used as a default.

alpha

Transparency value

⁠scalar<numeric|integer>(0>=val>=1)⁠ // default: NULL (optional)

An optional alpha transparency value for the color as single value in the range of 0 (fully transparent) to 1 (fully opaque). If not provided the fill color will either be fully opaque or use alpha information from the color value if it is supplied in the ⁠#RRGGBBAA⁠ format.

Value

A list object of class cell_styles.

Examples

Let's use the exibble dataset to create a simple, two-column gt table (keeping only the num and currency columns). Styles are added with tab_style() in two separate calls (targeting different body cells with the cells_body() helper function). With the cell_fill() helper function we define cells with a "lightblue" background in one instance, and "gray85" in the other.

exibble |>
  dplyr::select(num, currency) |>
  gt() |>
  fmt_number(decimals = 1) |>
  tab_style(
    style = cell_fill(color = "lightblue"),
    locations = cells_body(
      columns = num,
      rows = num >= 5000
    )
  ) |>
  tab_style(
    style = cell_fill(color = "gray85"),
    locations = cells_body(
      columns = currency,
      rows = currency < 100
    )
  )
This image of a table was generated from the first code example in the `cell_fill()` help file.

Function ID

8-26

Function Introduced

v0.2.0.5 (March 31, 2020)

See Also

Other helper functions: adjust_luminance(), cell_borders(), cell_text(), currency(), default_fonts(), escape_latex(), from_column(), google_font(), gt_latex_dependencies(), html(), md(), nanoplot_options(), pct(), px(), random_id(), row_group(), stub(), system_fonts(), unit_conversion()


rstudio/gt documentation built on Dec. 2, 2024, 11:05 a.m.