Skip to contents

Cell renderers for reactable::colDef() that translate team abbreviations (or player IDs) into <img> tags. Values that cannot be resolved are returned unchanged so the original text is shown. Logos and wordmarks get the team's full name as alt text, headshots "Player <id> headshot".

Usage

reactable_sdv_logos(
  league,
  variant = "default",
  height = 30,
  default_img = NULL,
  season = NULL,
  id_system = "auto",
  strict = FALSE
)

reactable_sdv_wordmarks(
  league,
  variant = "default",
  height = 30,
  default_img = NULL,
  season = NULL,
  id_system = "auto",
  strict = FALSE
)

reactable_sdv_headshots(
  league,
  height = 40,
  default_img = NULL,
  id_system = "espn"
)

Arguments

league

A league key from sdv_leagues().

variant

Character. "default", "dark", or a named variant from sdv_marks() ("scoreboard", "grayscale", ...); see sdv_logo_url(). A team without it gets its closest mark, and in the browser the image falls back to the default mark when the variant's file fails to load.

height

Numeric. Image height in pixels.

default_img

Character. Fallback image URL used when the value cannot be resolved. If NULL (the default) the raw value is shown instead.

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.

Value

A function with signature function(value, index) suitable for the cell 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(cell = reactable_sdv_logos(league = "nfl"), html = TRUE)
  )
)