Finding the 100 best Fantasy Football Performances of the last 10 years
Loading in the necessary Libraries
library(reactable)
library(reactablefmtr)
library(htmltools)
library(tidyverse)
library(htmlwidgets)
library(gt)
Setting color variables for use in reactable table
wsj_cream = '#F7F2E6'
highlight_cream = '#FEFCF4'
text_black = '#292727'
glizzy_grey = '#C4C4C4'
almost_white = '#F1F1F1'
Wrangle and clean data
ffp_react <- read.csv('/Users/trev/Desktop/Data Projects/R Files/all_time_ffp.csv')
ffp_react <- ffp_react %>%
slice_max(ffp, n = 100, with_ties = FALSE) %>%
mutate(rank = row_number()) %>%
mutate(headshot_url = coalesce(headshot_url, 'https://static.www.nfl.com/image/private/f_auto,q_auto/league/mdrlzgankwwjldxllgcx')) %>%
select(rank, headshot_url, 'Player' = player, 'Pos' = pos, team, 'Season' = season, 'Week' = week, 'Points' = ffp, pass_yds, pass_tds, rush_yds, rush_tds, rec, rec_yds, rec_tds, twopoints, fumbles, int)
ffp_react$Points <- round(ffp_react$Points, 1)
head(ffp_react, 5) %>% gt()
| rank | headshot_url | Player | Pos | team | Season | Week | Points | pass_yds | pass_tds | rush_yds | rush_tds | rec | rec_yds | rec_tds | twopoints | fumbles | int |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | https://static.www.nfl.com/image/private/f_auto,q_auto/league/mdrlzgankwwjldxllgcx | Jamaal Charles | RB | KC | 2013 | Week 15 | 59.5 | 0 | 0 | 20 | 1 | 8 | 195 | 4 | 0 | 0 | 0 |
| 2 | https://static.www.nfl.com/image/private/f_auto,q_auto/league/lsszbdnkusxc7mduw5be | Tyreek Hill | WR | KC | 2020 | Week 12 | 57.9 | 0 | 0 | 0 | 0 | 13 | 269 | 3 | 0 | 0 | 0 |
| 3 | https://static.www.nfl.com/image/private/f_auto,q_auto/league/uulstglrpmhqsvqyr5v3 | Alvin Kamara | RB | NO | 2020 | Week 16 | 56.2 | 0 | 0 | 155 | 6 | 3 | 17 | 0 | 0 | 0 | 0 |
| 4 | https://static.www.nfl.com/image/private/f_auto,q_auto/league/hwrzdfsng9bh4tba7uoe | Ja'Marr Chase | WR | CIN | 2021 | Week 17 | 55.6 | 0 | 0 | 0 | 0 | 11 | 266 | 3 | 0 | 0 | 0 |
| 5 | https://static.www.nfl.com/image/private/f_auto,q_auto/league/lhazttk4tjpi7ggf7du4 | Doug Martin | RB | TB | 2012 | Week 9 | 55.2 | 0 | 0 | 251 | 4 | 4 | 21 | 0 | 0 | 0 | 0 |
Create interactive table
ffp_table <- ffp_react %>% reactable(
., theme = reactableTheme(
color = text_black,
backgroundColor = almost_white,
borderColor = '#B8B8B8',
borderWidth = '2px',
cellPadding = '8px 12px'),
highlight = TRUE,
striped = TRUE,
bordered = FALSE,
fullWidth = TRUE,
style = list(fontFamily = 'Roboto Mono'),
defaultColDef = colDef(align = 'center', vAlign = 'center', style = list(fontSize =14)),
defaultPageSize = 8,
columnGroups = list(
colGroup(name = 'PASSING',
columns = c('pass_yds', 'pass_tds', 'int')),
colGroup(name = 'RUSHING',
columns = c('rush_yds', 'rush_tds', 'fumbles')),
colGroup(name = 'RECIEVING',
columns = c('rec', 'rec_yds', 'rec_tds'))),
columns = list(
rank = colDef(name = '#',
minWidth = 65,
style = list(fontFamily = 'staatliches', fontSize = 28, borderRight = '2px solid ##B8B8B8')
),
headshot_url = colDef(name = '',
minWidth = 110,
align = 'center',
cell = embed_img(height = 75, width = 105)),
Player = colDef(name = 'NAME',
style = list(fontFamily = 'staatliches', fontSize = 24),
align = 'center',
minWidth = 200,
cell = merge_column(., 'team', 'below', size = 20, merged_size = 14)),
Pos = colDef(name = 'POS',
minWidth = 75,
style = list(fontSize = 19, fontWeight = 700)),
team = colDef(show = FALSE),
Season = colDef(name = 'GAME',
minWidth = 75,
cell = merge_column(., "Week", "below")),
Week = colDef(show = FALSE),
Points = colDef(name = 'POINTS',
minWidth = 100,
style = list(fontSize = 19, borderLeft = '2px solid #B8B8B8', borderRight = '2px solid ##B8B8B8'),
cell = pill_buttons(., colors = '#292727', bold_text = TRUE)),
pass_yds = colDef(name = 'YDS',
width = 72,
style = highlight_max(.,font_color = 'green')),
pass_tds = colDef(name = 'TDS',
width = 72,
style = highlight_max(.,font_color = 'green')),
int = colDef(name = 'INT',
width = 72,
style = list(borderRight = '2px solid #B8B8B8')),
rush_yds = colDef(name = 'YDS',
width = 72,
style = highlight_max(.,font_color = 'green')),
rush_tds = colDef(name = 'TDS',
width = 72,
style = highlight_max(.,font_color = 'green')),
fumbles = colDef(name = 'FUM',
width = 72,
style = list(borderRight = '2px solid #B8B8B8')),
rec = colDef(name = 'REC',
width = 72,
style = highlight_max(.,font_color = 'green')),
rec_yds = colDef(name = 'YDS',
width = 72,
style = highlight_max(.,font_color = 'green')),
rec_tds = colDef(name = 'TDS',
width = 72,
style = highlight_max(., font_color = 'green')),
twopoints = colDef(name = '2PT',
width = 72,
style = list(borderLeft = '2px solid #B8B8B8'))))
ffp_table_final <- ffp_table %>%
htmlwidgets::prependContent(
tagList(
tags$div('Top 100 Fantasy Football Performances since 2012', style = 'font-size:42px;font-weight:bold;font-family:Staatliches;color:#292727;margin-bottom:0;display:inline-block;vertical-align:middle;'),
tags$h3('Based on ESPN standard PPR scoring', style="font-family:Roboto Mono;font-size:18px;margin-bottom:0;margin-top:0;font-weight:400;color:#292727;padding-left:0px;")))
ffp_table_final
Save table as an HTML widget
saveWidget(ffp_table_final, 'ffp_table_final.html', background = almost_white)