Translate player IDs to player headshots and render these
images in html tables with the 'gt' package. IDs are GSIS IDs for the NFL
("00-0033873", resolved through the headshot map sdvplotR publishes from
nflverse rosters to the player's NFL.com headshot) and ESPN athlete IDs for
every other sport, or as id_type says. IDs that resolve to no headshot
are left as text.
Usage
gt_sdv_headshots(
gt_object,
columns,
sport = c("nfl", "nba", "wnba", "mlb", "nhl", "cfb", "mbb", "wbb"),
height = 30,
locations = NULL,
id_type = NULL
)Arguments
- gt_object
A table object created using
gt::gt().- columns
The columns for which the image translation should be applied. Argument has no effect if
locationsis notNULL.- sport
Character string identifying the sport.
- height
The absolute height (px) of the image in the table cell.
- locations
If
NULL(the default), the function will render logos in argumentcolumns. Otherwise, the cell or set of cells to be associated with the team name transformation. Onlygt::cells_body(),gt::cells_stub(),gt::cells_column_labels(), andgt::cells_row_groups()helper functions can be used here.- id_type
Which ID system
player_idholds.NULL(the default) takes GSIS IDs for the NFL and ESPN athlete IDs for every other sport."espn"takes ESPN athlete IDs for any sport, the IDs in ESPN-sourced data such as hoopR's and wehoop'sespn_*()functions."league"takes the league's own ID: the GSIS ID for the NFL, the NBA Stats or WNBA StatsPERSON_ID(hoopR'snba_*(), wehoop'swnba_*()), the MLBAM ID (baseballr'smlb_*(), Baseball Savant) for MLB, or the NHL API player ID (fastRhockey'snhl_*()andload_nhl_*()) for the NHL, drawn from that league's image CDN; college sports have no league option. ESPN and league IDs other than GSIS are plain digits, so a mismatch draws the wrong player or no image rather than an error. League CDNs draw a silhouette for an unknown ID, and the NBA and WNBA CDNs refuse requests from datacenter IPs, so a plot drawn on CI or a server can come back without those headshots.



