OwenStOnge commited on
Commit
3c64c4e
·
verified ·
1 Parent(s): b4149d8

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +78 -1
app.R CHANGED
@@ -912,7 +912,19 @@ app_ui <- fluidPage(
912
  # =============================================
913
  # TAB 9: OAA Leaderboard (placeholder)
914
  # =============================================
915
- tabPanel("OAA Leaderboard", h4("Coming Soon", style="text-align:center;color:darkcyan;padding:60px;"))
 
 
 
 
 
 
 
 
 
 
 
 
916
  )
917
  )
918
 
@@ -1124,6 +1136,71 @@ server <- function(input, output, session) {
1124
  obs_outs = input$dp_outs,
1125
  Opponent = input$dp_opponent)
1126
  })
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1127
  }
1128
 
1129
  shinyApp(ui, server)
 
912
  # =============================================
913
  # TAB 9: OAA Leaderboard (placeholder)
914
  # =============================================
915
+ tabPanel("OAA Leaderboard",
916
+ fluidRow(
917
+ column(3,
918
+ checkboxGroupInput("lb_year_select", "Year:",
919
+ choices = c("2025", "2026"), selected = c("2025", "2026"), inline = TRUE)),
920
+ column(6,
921
+ checkboxGroupInput("lb_position_select", "Position:",
922
+ choices = c("LF","CF","RF","SS","2B","3B","1B"),
923
+ selected = c("LF","CF","RF","SS","2B","3B","1B"), inline = TRUE))
924
+ ),
925
+ hr(),
926
+ gt_output("lb_table")
927
+ )
928
  )
929
  )
930
 
 
1136
  obs_outs = input$dp_outs,
1137
  Opponent = input$dp_opponent)
1138
  })
1139
+
1140
+ # ============================================================
1141
+ # OAA LEADERBOARD
1142
+ # ============================================================
1143
+ lb_data <- reactive({
1144
+ req(isTRUE(authed()), input$lb_year_select, input$lb_position_select)
1145
+ yrs <- input$lb_year_select
1146
+ pos <- input$lb_position_select
1147
+
1148
+ of_positions <- intersect(pos, c("LF","CF","RF"))
1149
+ if_positions <- intersect(pos, c("SS","2B","3B","1B"))
1150
+
1151
+ of_combined <- NULL
1152
+ if (length(of_positions) > 0) {
1153
+ of_pool <- if (all(c("2025","2026") %in% yrs)) {
1154
+ bind_rows(OF_OAA_25, OF_OAA_26)
1155
+ } else if ("2025" %in% yrs) { OF_OAA_25 } else { OF_OAA_26 }
1156
+
1157
+ of_combined <- of_pool %>%
1158
+ filter(hit_location %in% of_positions) %>%
1159
+ mutate(year = format(as.Date(Date), "%Y")) %>%
1160
+ filter(year %in% yrs) %>%
1161
+ group_by(Player = obs_player, Position = hit_location) %>%
1162
+ summarize(OAA = round(sum(OAA, na.rm = TRUE), 2),
1163
+ Plays = n(), .groups = "drop")
1164
+ }
1165
+
1166
+ if_combined <- NULL
1167
+ if (length(if_positions) > 0) {
1168
+ if_pool <- if (all(c("2025","2026") %in% yrs)) {
1169
+ bind_rows(IF_OAA_25, IF_OAA_26)
1170
+ } else if ("2025" %in% yrs) { IF_OAA_25 } else { IF_OAA_26 }
1171
+
1172
+ if_combined <- if_pool %>%
1173
+ filter(obs_player %in% if_positions) %>%
1174
+ mutate(year = format(as.Date(Date), "%Y")) %>%
1175
+ filter(year %in% yrs) %>%
1176
+ group_by(Player = obs_player_name, Position = obs_player) %>%
1177
+ summarize(OAA = round(sum(OAA, na.rm = TRUE), 2),
1178
+ Plays = n(), .groups = "drop")
1179
+ }
1180
+
1181
+ bind_rows(of_combined, if_combined) %>%
1182
+ arrange(desc(OAA))
1183
+ })
1184
+
1185
+ output$lb_table <- render_gt({
1186
+ req(nrow(lb_data()) > 0)
1187
+ lb_data() %>%
1188
+ mutate(Rank = row_number()) %>%
1189
+ dplyr::select(Rank, Player, Position, OAA, Plays) %>%
1190
+ gt() %>%
1191
+ gt_theme_guardian() %>%
1192
+ tab_header(title = "OAA Leaderboard") %>%
1193
+ cols_align(align = "center", columns = everything()) %>%
1194
+ cols_align(align = "left", columns = Player) %>%
1195
+ fmt_number(columns = OAA, decimals = 2) %>%
1196
+ tab_options(
1197
+ heading.background.color = "darkcyan",
1198
+ column_labels.background.color = "darkcyan",
1199
+ table.border.top.color = "peru",
1200
+ table.border.bottom.color = "peru") %>%
1201
+ tab_style(style = cell_text(color = "white"),
1202
+ locations = cells_title(groups = "title"))
1203
+ })
1204
  }
1205
 
1206
  shinyApp(ui, server)