TimStats commited on
Commit
e2770b5
·
verified ·
1 Parent(s): e3d3e22

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +43 -31
app.R CHANGED
@@ -311,8 +311,8 @@ FSL_processed <- FSL %>%
311
 
312
  # Available stats for the UI
313
  available_stats <- c("Pitches", "Avg Velo", "Top Velo", "TimStuff", "Max EV", "Avg EV",
314
- "EV90", "Avg LA", "stdevLA", "HardHit%", "Barrel%", "Sweet Spot%",
315
- "xwOBA", "xwOBACON", "Contact%", "ZCon%", "ZSwing%", "OCon%",
316
  "Chase%", "SwStr%", "Whiff%", "Zone%", "Strike%", "Swing%",
317
  "Spin Rate", "Extension", "IVB", "HB", "CSW%", "Arm Angle", "Bat Speed")
318
 
@@ -386,7 +386,7 @@ server <- function(input, output, session) {
386
  if ("AAA" %in% input$level) AAA_processed,
387
  if ("FSL" %in% input$level) FSL_processed
388
  )
389
-
390
  # First group and calculate all stats
391
  grouped_data <- combined_data %>%
392
  group_by(across(all_of(input$group))) %>%
@@ -402,9 +402,9 @@ server <- function(input, output, session) {
402
  'stdevLA' = sd(hit_angle, na.rm = TRUE),
403
  'HardHit%' = mean(HardHitCheck[InPlayCheck == TRUE], na.rm = TRUE) * 100,
404
  'Barrel%' = mean(barrel[InPlayCheck == TRUE], na.rm = TRUE) * 100,
405
- 'Sweet Spot%' = mean(SweetSpotCheck[InPlayCheck == TRUE], na.rm = TRUE) * 100,
406
  'xwOBA' = mean(expected_woba, na.rm = TRUE),
407
- 'xwOBACON' = mean(expected_woba[InPlayCheck == TRUE], na.rm = TRUE),
408
  'Contact%' = mean(ConCheck[SwingCheck == TRUE], na.rm = TRUE) * 100,
409
  'ZCon%' = mean(ConCheck[ZoneCheck == TRUE & SwingCheck == TRUE], na.rm = TRUE) * 100,
410
  'ZSwing%' = mean(SwingCheck[ZoneCheck == TRUE], na.rm = TRUE) * 100,
@@ -462,32 +462,44 @@ server <- function(input, output, session) {
462
  # Tabulator rendering with formatting
463
  output$table <- renderTabulator({
464
  req(processed_data())
465
- column_defs <- c(
466
- # Group columns
467
- map(input$group, function(col) {
468
- list(field = col, title = col, width = 175) # reduced from 250
469
- }),
470
- # Stat columns
471
- map(input$stats, function(col) {
472
- list(
473
- field = col,
474
- title = col,
475
- width = 110, # reduced from 150
476
- formatter = if(col %in% c("xwOBA", "xwOBACON")) "number" else "number",
477
- formatterParams = if(col %in% c("xwOBA", "xwOBACON")) {
478
- list(precision = 3)
479
- } else {
480
- list(precision = 1)
481
- }
482
- )
483
- })
484
- )
485
- tabulator(processed_data(),
486
- options = list(
487
- selectable = TRUE,
488
- layout = "fitColumns",
489
- columns = column_defs
490
- )
 
 
 
 
 
 
 
 
 
 
 
 
491
  )
492
  })
493
  # Add observers for filter management and other reactive elements
 
311
 
312
  # Available stats for the UI
313
  available_stats <- c("Pitches", "Avg Velo", "Top Velo", "TimStuff", "Max EV", "Avg EV",
314
+ "EV90", "Avg LA", "stdevLA", "HardHit%", "Barrel%", "SwSpt%",
315
+ "xwOBA", "xDamage", "Contact%", "ZCon%", "ZSwing%", "OCon%",
316
  "Chase%", "SwStr%", "Whiff%", "Zone%", "Strike%", "Swing%",
317
  "Spin Rate", "Extension", "IVB", "HB", "CSW%", "Arm Angle", "Bat Speed")
318
 
 
386
  if ("AAA" %in% input$level) AAA_processed,
387
  if ("FSL" %in% input$level) FSL_processed
388
  )
389
+ filter(game_date >= input$date_range[1] & game_date <= input$date_range[2])
390
  # First group and calculate all stats
391
  grouped_data <- combined_data %>%
392
  group_by(across(all_of(input$group))) %>%
 
402
  'stdevLA' = sd(hit_angle, na.rm = TRUE),
403
  'HardHit%' = mean(HardHitCheck[InPlayCheck == TRUE], na.rm = TRUE) * 100,
404
  'Barrel%' = mean(barrel[InPlayCheck == TRUE], na.rm = TRUE) * 100,
405
+ 'SwSpt%' = mean(SweetSpotCheck[InPlayCheck == TRUE], na.rm = TRUE) * 100,
406
  'xwOBA' = mean(expected_woba, na.rm = TRUE),
407
+ 'xDamage' = mean(expected_woba[InPlayCheck == TRUE], na.rm = TRUE),
408
  'Contact%' = mean(ConCheck[SwingCheck == TRUE], na.rm = TRUE) * 100,
409
  'ZCon%' = mean(ConCheck[ZoneCheck == TRUE & SwingCheck == TRUE], na.rm = TRUE) * 100,
410
  'ZSwing%' = mean(SwingCheck[ZoneCheck == TRUE], na.rm = TRUE) * 100,
 
462
  # Tabulator rendering with formatting
463
  output$table <- renderTabulator({
464
  req(processed_data())
465
+ group_columns <- map(input$group, function(col) {
466
+ list(
467
+ field = col,
468
+ title = col,
469
+ width = 175,
470
+ headerFilter = "input", # Add text filtering
471
+ headerFilterPlaceholder = paste("Filter", col)
472
+ )
473
+ })
474
+
475
+ # Create column definitions for stat columns
476
+ stat_columns <- map(input$stats, function(col) {
477
+ list(
478
+ field = col,
479
+ title = col,
480
+ width = 110,
481
+ formatter = if(col %in% c("xwOBA", "xDamage")) "number" else "number",
482
+ formatterParams = if(col %in% c("xwOBA", "xDamage")) {
483
+ list(precision = 3)
484
+ } else {
485
+ list(precision = 1)
486
+ }
487
+ )
488
+ })
489
+
490
+ # Combine column definitions
491
+ column_defs <- c(group_columns, stat_columns)
492
+
493
+ tabulator(
494
+ processed_data(),
495
+ options = list(
496
+ pagination = TRUE, # Enable pagination
497
+ paginationSize = 10, # Set page size to 10 rows
498
+ paginationSizeSelector = c(10, 25, 50, 100), # Allow users to change page size
499
+ selectable = TRUE,
500
+ layout = "fitColumns",
501
+ columns = column_defs
502
+ )
503
  )
504
  })
505
  # Add observers for filter management and other reactive elements