-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreactive_table.R
165 lines (147 loc) · 4.31 KB
/
reactive_table.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Reactable table code:
# Need to pick it apart
library(reactablefmtr)
library(htmltools)
library(crosstalk) # for control filters
### load data from 538
data <- read.csv(file = "RAPTOR_by_team_19-20.csv")
### create shared dataset for crosstalk
crosstalk_data <- SharedData$new(pg_stats)
### crosstalk team filter
team_filter <- filter_select(
id = "team",
label = "TEAM",
sharedData = crosstalk_data,
group = ~ team_display_name
)
### crosstalk conference filter
conference_filter <- filter_select(
id = "conf",
label = "CONFERENCE",
sharedData = crosstalk_data,
group = ~ CONFERENCE
)
### crosstalk minutes filter
minutes_filter <- filter_slider(
id = "minutes",
label = "MINUTES PLAYED",
sharedData = crosstalk_data,
column = ~ minutes,
ticks = TRUE,
dragRange = FALSE,
step = 100,
width = "60%"
)
### load font from google fonts
htmltools::tags$link(href = "https://fonts.googleapis.com/css?family=Chivo:400,600,700&display=swap", rel = "stylesheet")
nba_table <- reactable(
crosstalk_data,
theme = fivethirtyeight(centered = TRUE),
compact = TRUE,
columnGroups = list(
colGroup(name = "OVERALL STATS", columns = c("field_goals_made","three_point_field_goals_made","free_throws_made","assists","rebounds"))
),
showSortIcon = FALSE,
searchable = TRUE,
language = reactableLang(
searchPlaceholder = "SEARCH FOR A PLAYER..."
),
defaultPageSize = 20,
columns = list(
team_display_name = colDef(show = FALSE),
team_name = colDef(show = FALSE),
CONFERENCE = colDef(show = FALSE),
TEAM_LOGO = colDef(
name = "Team",
maxWidth = 70,
align = "center",
cell = embed_img(height = 25, width = 40),
style = list(borderRight = "1px solid #777")
),
athlete_display_name = colDef(maxWidth = 150,
name = "Player",
# merge the "Name" column with the "Postion" column and place it below
cell = merge_column(pg_stats, "team_name", merged_position = "below"),
style = list(borderRight = "1px solid #777")),
minutes = colDef(
name = "Minutes",
maxWidth = 85,
align = "center",
cell = icon_assign(
pg_stats,
icon = "stopwatch",
fill_color = "#555555",
buckets = 5
),
style = list(borderRight = "1px dashed rgba(0, 0, 0, 0.3)")
),
field_goals_made = colDef(
name = "AFG",
maxWidth = 60,
style = color_scales(pg_stats, colors = c("#fd84a9", "white", "#42c2ca")),
format = colFormat(digits =2)
),
three_point_field_goals_made = colDef(
name = "3PAFG",
maxWidth = 60,
style = color_scales(pg_stats, colors = c("#fd84a9", "white", "#42c2ca")),
format = colFormat(digits =2)
),
free_throws_made = colDef(
name = "AFT",
maxWidth = 60,
style = color_scales(pg_stats, colors = c("#fd84a9", "white", "#42c2ca")),
format = colFormat(digits =2)
),
assists = colDef(
name = "AST",
maxWidth = 60,
style = color_scales(pg_stats, colors = c("#fd84a9", "white", "#42c2ca")),
format = colFormat(digits =2)
),
rebounds = colDef(
name = "REB",
maxWidth = 60,
style = color_scales(pg_stats, colors = c("#fd84a9", "white", "#42c2ca")),
format = colFormat(digits =2)
),
total_points = colDef(
name = "TPTS",
maxWidth = 100,
align = "center",
cell = data_bars(
pg_stats,
fill_color = c("#de425b", "#ec9c9d", "#8cbcac", "#488f31"),
number_fmt = scales::comma_format(),
round_edges = TRUE,
border_style = "solid",
border_color = "gold",
border_width = ".8px",
text_position = "above"),
style = list(borderLeft = "1px dashed rgba(0, 0, 0, 0.3)")
)
)
)
### display crosstalk filters
div(bscols(
widths = c(4, NA, NA),
list(team_filter,
conference_filter,
minutes_filter))
)
library(shiny)
# display crosstalk filters
div(
fluidRow(
column(4, team_filter),
column(4, conference_filter),
column(4, minutes_filter)
)
)
# display table
div(nba_table)
### display table
div(nba_table)
## The issue was that you have to reference the og data frame
##
# Points assists and rebounds seem to be the most important stats