Skip to contents

Style functions for reactable::colDef() that color cells with a team's primary or secondary color: a horizontal bar whose length is proportional to the cell value, or a translucent background fill.

Usage

reactable_sdv_team_color_bar(
  data,
  team_col,
  league,
  which = c("primary", "secondary"),
  max_value = NULL,
  na_color = "grey70",
  season = NULL,
  id_system = "auto",
  strict = FALSE
)

reactable_sdv_team_color_bg(
  data,
  team_col,
  league,
  which = c("primary", "secondary"),
  alpha = 0.15,
  na_color = "grey70",
  season = NULL,
  id_system = "auto",
  strict = FALSE
)

Arguments

data

The data frame passed to reactable::reactable(). Needed to look up the team of each row.

team_col

Character. Name of the column in data holding team abbreviations.

league

A league key from sdv_leagues().

which

Character. "primary" or "secondary" team color.

max_value

Numeric. Reference value that fills the whole cell. If NULL (the default), the maximum of the styled column is used.

na_color

Color used when a team cannot be resolved.

season

NULL for today's mark, or a season (or one per team): the mark the team wore that season where the archive dates its marks.

id_system

"auto" (try every id system in priority order) or one id system: "team_id", "espn", "espn_abbr", "nhl", "nflverse", "mlbstats", "nba_api", "hockeytech", "ncaa", "pff", "cricinfo", "cfbd", "bref", "sportsipy", "fangraphs", "yahoo", "kenpom", "torvik", "sdvplotr", "name", or one "auto" never tries because its numbers overlap ESPN's: "nhl_id" (NHL stats API ids), "fox", "cbs", "sports247" (247Sports team and institution ids) or "on3".

strict

If TRUE, a value that does not resolve is an error; otherwise it becomes NA with one warning per call.

alpha

Numeric. Opacity of the background fill in [0, 1].

Value

A function with signature function(value, index, name) suitable for the style argument of reactable::colDef().

Examples

library(reactable)
library(sdvplotR)

df <- data.frame(team = c("KC", "BUF", "SF"), wins = c(13, 12, 11))

reactable(
  df,
  columns = list(
    team = colDef(style = reactable_sdv_team_color_bg(df, "team", league = "nfl")),
    wins = colDef(style = reactable_sdv_team_color_bar(df, "team", league = "nfl"))
  )
)