Skip to contents

Renders the same few rows through each gt_theme_* function in the package and lays the results out in a grid, one panel per theme, labeled with its name.

Usage

gt_theme_preview(
  data,
  themes = NULL,
  n = 5,
  ncol = 3,
  density = "compact",
  file = NULL,
  ...
)

Arguments

data

A data frame. A gt table is also accepted, in which case its underlying data is used.

themes

Character. The theme functions to show, by name. If NULL, every gt_theme_* in the package is used. Defaults to NULL.

n

Integer. How many rows of data to show in each panel. Defaults to 5.

ncol

Integer. The number of panels across. Defaults to 3.

density

Character. A density passed to every theme, so the panels are comparable. If NULL, each theme uses its own default. Defaults to "compact".

file

Optional. A path to write a PNG to. If NULL, the grid is returned for the viewer. Defaults to NULL.

...

Further arguments passed to gt_grid(), such as gap or bg.

Value

Displays the grid in the viewer, or writes it to file.

Details

Each panel is captioned with the theme's name in a neutral style, set outside the table. Using each theme's own heading instead would let a wide display title stretch its panel out of shape.

Themes that take extra arguments, such as style on gt_theme_sofa(), are shown at their defaults.

See also

gt_grid(), which does the layout.

Examples

gt_theme_preview(
  mtcars[c("mpg", "cyl", "hp")],
  themes = c("gt_theme_sdv", "gt_theme_kenpom", "gt_theme_athletic")
)
sdv
mpg cyl hp
21.0 6 110
21.0 6 110
22.8 4 93
21.4 6 110
18.7 8 175
kenpom
toss_out_spanner_dev
mpg cyl hp
21.0 6 110
21.0 6 110
22.8 4 93
21.4 6 110
18.7 8 175
athletic
mpg cyl hp
21.0 6 110
21.0 6 110
22.8 4 93
21.4 6 110
18.7 8 175
if (FALSE) { # interactive() && rlang::is_installed("webshot2") && isTRUE(file.exists(chromote::find_chrome())) # a subset, saved as one wide image; saving needs a headless Chrome (webshot2) # \donttest{ gt_theme_preview( iris, themes = c("gt_theme_broadsheet", "gt_theme_swiss", "gt_theme_midnight"), ncol = 3, file = tempfile(fileext = ".png") ) # } }