OwenStOnge commited on
Commit
1c19f6f
·
verified ·
1 Parent(s): cb69812

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +42 -47
app.R CHANGED
@@ -950,62 +950,57 @@ server <- function(input, output, session) {
950
  # ============================================================
951
  # POPULATE OF PLAYER DROPDOWN
952
  # ============================================================
953
- observe({
954
- req(authed())
955
- req(input$of_year_select)
956
- req(input$of_position)
957
- d <- of_data()
958
- pos <- input$of_position
959
- if (pos %in% c("LF","CF","RF")) {
960
- players <- sort(unique(d$obs_player[d$hit_location == pos]))
961
- } else {
962
- players <- sort(unique(d$obs_player))
963
- }
964
- updateSelectInput(session, "of_player", choices = players,
965
- selected = if (length(players) > 0) players[1] else NULL)
966
- })
967
 
968
  # ============================================================
969
  # POPULATE IF PLAYER DROPDOWN
970
  # ============================================================
971
- observe({
972
- req(authed())
973
- req(input$if_year_select)
974
- req(input$if_position)
975
- d <- if_data()
976
- pos <- input$if_position
977
- if (pos %in% c("SS","2B","3B","1B")) {
978
- players <- sort(unique(d$obs_player_name[d$obs_player == pos]))
979
- } else {
980
- players <- sort(unique(d$obs_player_name))
981
- }
982
- updateSelectInput(session, "if_player", choices = players,
983
- selected = if (length(players) > 0) players[1] else NULL)
984
- })
985
 
986
  # ============================================================
987
  # POPULATE DEFENSIVE POSITIONING DROPDOWNS
988
  # ============================================================
989
- observe({
990
- req(authed())
991
- teams <- sort(unique(def_pos_data$PitcherTeam))
992
- updateSelectInput(session, "dp_team", choices = teams,
993
- selected = if ("CCU_CHN" %in% teams) "CCU_CHN" else teams[1])
994
- })
995
 
996
- observe({
997
- req(authed())
998
- req(input$dp_team)
999
- td <- def_pos_data %>% filter(PitcherTeam == input$dp_team)
1000
- pitchers <- sort(unique(td$Pitcher))
1001
- batters <- sort(unique(td$Batter))
1002
- opponents <- sort(unique(td$BatterTeam))
1003
- counts <- sort(unique(td$pitch_count))
1004
- updateSelectInput(session, "dp_pitcher", choices = c("No Filter", pitchers))
1005
- updateSelectInput(session, "dp_hitter", choices = c("No Filter", batters))
1006
- updateSelectInput(session, "dp_opponent", choices = c("No Filter", opponents))
1007
- updateSelectInput(session, "dp_count", choices = c("No Filter", counts))
1008
- })
1009
 
1010
  # ============================================================
1011
  # OUTFIELD OAA OUTPUTS
 
950
  # ============================================================
951
  # POPULATE OF PLAYER DROPDOWN
952
  # ============================================================
953
+ observeEvent(list(authed(), input$of_year_select, input$of_position), {
954
+ req(isTRUE(authed()), input$of_year_select, input$of_position)
955
+ d <- of_data()
956
+ pos <- input$of_position
957
+ if (pos %in% c("LF","CF","RF")) {
958
+ players <- sort(unique(d$obs_player[d$hit_location == pos]))
959
+ } else {
960
+ players <- sort(unique(d$obs_player))
961
+ }
962
+ updateSelectInput(session, "of_player", choices = players,
963
+ selected = if (length(players) > 0) players[1] else NULL)
964
+ }, ignoreInit = TRUE)
 
 
965
 
966
  # ============================================================
967
  # POPULATE IF PLAYER DROPDOWN
968
  # ============================================================
969
+ observeEvent(list(authed(), input$if_year_select, input$if_position), {
970
+ req(isTRUE(authed()), input$if_year_select, input$if_position)
971
+ d <- if_data()
972
+ pos <- input$if_position
973
+ if (pos %in% c("SS","2B","3B","1B")) {
974
+ players <- sort(unique(d$obs_player_name[d$obs_player == pos]))
975
+ } else {
976
+ players <- sort(unique(d$obs_player_name))
977
+ }
978
+ updateSelectInput(session, "if_player", choices = players,
979
+ selected = if (length(players) > 0) players[1] else NULL)
980
+ }, ignoreInit = TRUE)
 
 
981
 
982
  # ============================================================
983
  # POPULATE DEFENSIVE POSITIONING DROPDOWNS
984
  # ============================================================
985
+ observeEvent(authed(), {
986
+ req(isTRUE(authed()))
987
+ teams <- sort(unique(def_pos_data$PitcherTeam))
988
+ updateSelectInput(session, "dp_team", choices = teams,
989
+ selected = if ("CCU_CHN" %in% teams) "CCU_CHN" else teams[1])
990
+ }, ignoreInit = TRUE)
991
 
992
+ observeEvent(list(authed(), input$dp_team), {
993
+ req(isTRUE(authed()), input$dp_team)
994
+ td <- def_pos_data %>% filter(PitcherTeam == input$dp_team)
995
+ pitchers <- sort(unique(td$Pitcher))
996
+ batters <- sort(unique(td$Batter))
997
+ opponents <- sort(unique(td$BatterTeam))
998
+ counts <- sort(unique(td$pitch_count))
999
+ updateSelectInput(session, "dp_pitcher", choices = c("No Filter", pitchers))
1000
+ updateSelectInput(session, "dp_hitter", choices = c("No Filter", batters))
1001
+ updateSelectInput(session, "dp_opponent", choices = c("No Filter", opponents))
1002
+ updateSelectInput(session, "dp_count", choices = c("No Filter", counts))
1003
+ }, ignoreInit = TRUE)
 
1004
 
1005
  # ============================================================
1006
  # OUTFIELD OAA OUTPUTS