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 that needs nothing but the table is used, which leaves out gt_theme_source() (it needs a registry name) and gt_theme_sdv_team() (its league argument has no default). 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

What gt_grid() returns: an htmltools::browsable() tag list of the previews, which prints in the viewer; with file, invisibly file after writing the PNG to it.

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

nfl <- subset(
  sdv_example_standings, league == "nfl",
  c(team_name, wins, losses, win_pct)
)
gt_theme_preview(
  nfl,
  themes = c("gt_theme_sdv", "gt_theme_kenpom", "gt_theme_athletic")
)
sdv
team_name wins losses win_pct
New England Patriots 14 3 0.824
Buffalo Bills 12 5 0.706
Miami Dolphins 7 10 0.412
New York Jets 3 14 0.176
Pittsburgh Steelers 10 7 0.588
kenpom
toss_out_spanner_dev
team_name wins losses win_pct
New England Patriots 14 3 0.824
Buffalo Bills 12 5 0.706
Miami Dolphins 7 10 0.412
New York Jets 3 14 0.176
Pittsburgh Steelers 10 7 0.588
athletic
team_name wins losses win_pct
New England Patriots 14 3 0.824
Buffalo Bills 12 5 0.706
Miami Dolphins 7 10 0.412
New York Jets 3 14 0.176
Pittsburgh Steelers 10 7 0.588
# a subset, saved as one wide image; saving needs a headless Chrome (webshot2) # \donttest{ if (interactive() && rlang::is_installed("webshot2") && isTRUE(file.exists(chromote::find_chrome()))) { nba <- subset( sdv_example_standings, league == "nba", c(team_name, wins, losses, win_pct) ) gt_theme_preview( nba, themes = c("gt_theme_broadsheet", "gt_theme_swiss", "gt_theme_midnight"), ncol = 3, file = tempfile(fileext = ".png") ) } # }