DaveM2430 commited on
Commit
1d40485
Β·
verified Β·
1 Parent(s): c16fa01

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +42 -56
app.R CHANGED
@@ -522,22 +522,38 @@ server <- function(input, output, session) {
522
  }
523
  })
524
 
 
 
 
 
 
 
 
 
 
 
 
525
  # ── Pitcher table ────────────────────────────────────────────────────────────
526
  output$pitcher_table <- renderDT({
527
  req(stats_table(), nrow(stats_table()) > 0)
528
  dt <- stats_table()
529
 
530
- # ── Color ranges (uncomment and set when ready) ───────────────────────────
531
- # zone_pct_range <- c(42, 53)
532
- # strike_pct_range <- c(58, 67)
533
- # fb_velo_range <- c(88, 95)
534
- # kb_range <- c(1.5, 4.0)
535
- # whiff_range <- c(15, 35)
536
- # chase_range <- c(25, 40)
537
- # hardhit_range <- c(25, 42)
538
- # stuff_range <- c(90, 110)
539
- # loc_range <- c(90, 110)
540
- # ─────────────────────────────────────────────────────────────────────────
 
 
 
 
 
541
 
542
  datatable(
543
  dt,
@@ -565,51 +581,21 @@ server <- function(input, output, session) {
565
  }")
566
  )
567
  ) %>%
568
- formatStyle("FB Velo",
569
- backgroundColor = styleInterval(c(85, 88, 91, 93),
570
- c("#ff6666","#ffaa88","#ffeecc","#ffffaa","#aaffaa"))) %>%
571
- formatStyle("Zone%",
572
- backgroundColor = styleInterval(c(43, 46, 49, 53),
573
- c("#ff6666","#ffaa88","#ffeecc","#ffffaa","#aaffaa"))) %>%
574
- formatStyle("Strike%",
575
- backgroundColor = styleInterval(c(57, 60, 63, 66),
576
- c("#ff6666","#ffaa88","#ffeecc","#ffffaa","#aaffaa"))) %>%
577
- formatStyle("K/BB",
578
- backgroundColor = styleInterval(c(1.2, 1.8, 2.5, 3.8),
579
- c("#ff6666","#ffaa88","#ffeecc","#ffffaa","#aaffaa"))) %>%
580
- formatStyle("Whiff%",
581
- backgroundColor = styleInterval(c(17, 21, 25, 31),
582
- c("#ff6666","#ffaa88","#ffeecc","#ffffaa","#aaffaa"))) %>%
583
- formatStyle("Chase%",
584
- backgroundColor = styleInterval(c(19, 22, 25, 29),
585
- c("#ff6666","#ffaa88","#ffeecc","#ffffaa","#aaffaa"))) %>%
586
- formatStyle("Hard Hit%",
587
- backgroundColor = styleInterval(c(26, 31, 37, 43),
588
- c("#aaffaa","#ffffaa","#ffeecc","#ffaa88","#ff6666"))) %>%
589
- formatStyle("GB%",
590
- backgroundColor = styleInterval(c(33, 39, 45, 51),
591
- c("#ff6666","#ffaa88","#ffeecc","#ffffaa","#aaffaa"))) %>%
592
- formatStyle("FB%",
593
- backgroundColor = styleInterval(c(21, 25, 29, 34),
594
- c("#aaffaa","#ffffaa","#ffeecc","#ffaa88","#ff6666"))) %>%
595
- formatStyle("LD%",
596
- backgroundColor = styleInterval(c(17, 20, 23, 27),
597
- c("#aaffaa","#ffffaa","#ffeecc","#ffaa88","#ff6666"))) %>%
598
- formatStyle("Stuff+",
599
- backgroundColor = styleInterval(c(85, 92, 100, 108),
600
- c("#ff6666","#ffaa88","#ffeecc","#ffffaa","#aaffaa"))) %>%
601
- formatStyle("Location+",
602
- backgroundColor = styleInterval(c(85, 92, 100, 108),
603
- c("#ff6666","#ffaa88","#ffeecc","#ffffaa","#aaffaa"))) %>%
604
- formatStyle("ERA",
605
- backgroundColor = styleInterval(c(3.2, 4.5, 6.0, 8.0),
606
- c("#aaffaa","#ffffaa","#ffeecc","#ffaa88","#ff6666"))) %>%
607
- formatStyle("FIP",
608
- backgroundColor = styleInterval(c(3.2, 4.0, 5.0, 6.0),
609
- c("#aaffaa","#ffffaa","#ffeecc","#ffaa88","#ff6666"))) %>%
610
- formatStyle("WHIP",
611
- backgroundColor = styleInterval(c(1.05, 1.3, 1.6, 1.9),
612
- c("#aaffaa","#ffffaa","#ffeecc","#ffaa88","#ff6666"))) %>%
613
  formatStyle("Portal",
614
  color = styleEqual(c("Yes","No"), c("#00840D","#aaaaaa")),
615
  fontWeight = styleEqual(c("Yes","No"), c("700","400"))
 
522
  }
523
  })
524
 
525
+ make_color_ramp <- function(values, low, high, flip = FALSE,
526
+ colors = c("#E1463E","#CDCD00","#00840D")) {
527
+ ramp <- colorRamp(if (flip) rev(colors) else colors)
528
+ sapply(values, function(v) {
529
+ if (is.na(v)) return("#ffffff")
530
+ norm <- pmax(0, pmin(1, (v - low) / (high - low)))
531
+ rgb_vals <- ramp(norm)
532
+ rgb(rgb_vals[1], rgb_vals[2], rgb_vals[3], maxColorValue = 255)
533
+ })
534
+ }
535
+
536
  # ── Pitcher table ────────────────────────────────────────────────────────────
537
  output$pitcher_table <- renderDT({
538
  req(stats_table(), nrow(stats_table()) > 0)
539
  dt <- stats_table()
540
 
541
+ # compute row-level colors
542
+ col_fbvelo <- make_color_ramp(dt$`FB Velo`, 85, 93)
543
+ col_zone <- make_color_ramp(dt$`Zone%`, 43, 53)
544
+ col_strike <- make_color_ramp(dt$`Strike%`, 57, 66)
545
+ col_kbb <- make_color_ramp(dt$`K/BB`, 1.2, 3.8)
546
+ col_whiff <- make_color_ramp(dt$`Whiff%`, 17, 31)
547
+ col_chase <- make_color_ramp(dt$`Chase%`, 19, 29)
548
+ col_hh <- make_color_ramp(dt$`Hard Hit%`, 26, 43, flip = TRUE)
549
+ col_gb <- make_color_ramp(dt$`GB%`, 33, 51)
550
+ col_fb <- make_color_ramp(dt$`FB%`, 21, 34, flip = TRUE)
551
+ col_ld <- make_color_ramp(dt$`LD%`, 17, 27, flip = TRUE)
552
+ col_stuff <- make_color_ramp(dt$`Stuff+`, 85, 110)
553
+ col_loc <- make_color_ramp(dt$`Location+`, 85, 110)
554
+ col_era <- make_color_ramp(dt$ERA, 3.2, 8.0, flip = TRUE)
555
+ col_fip <- make_color_ramp(dt$FIP, 3.2, 6.0, flip = TRUE)
556
+ col_whip <- make_color_ramp(dt$WHIP, 1.05,1.9, flip = TRUE)
557
 
558
  datatable(
559
  dt,
 
581
  }")
582
  )
583
  ) %>%
584
+ formatStyle("FB Velo", backgroundColor = styleEqual(dt$`FB Velo`, col_fbvelo)) %>%
585
+ formatStyle("Zone%", backgroundColor = styleEqual(dt$`Zone%`, col_zone)) %>%
586
+ formatStyle("Strike%", backgroundColor = styleEqual(dt$`Strike%`, col_strike)) %>%
587
+ formatStyle("K/BB", backgroundColor = styleEqual(dt$`K/BB`, col_kbb)) %>%
588
+ formatStyle("Whiff%", backgroundColor = styleEqual(dt$`Whiff%`, col_whiff)) %>%
589
+ formatStyle("Chase%", backgroundColor = styleEqual(dt$`Chase%`, col_chase)) %>%
590
+ formatStyle("Hard Hit%", backgroundColor = styleEqual(dt$`Hard Hit%`, col_hh)) %>%
591
+ formatStyle("GB%", backgroundColor = styleEqual(dt$`GB%`, col_gb)) %>%
592
+ formatStyle("FB%", backgroundColor = styleEqual(dt$`FB%`, col_fb)) %>%
593
+ formatStyle("LD%", backgroundColor = styleEqual(dt$`LD%`, col_ld)) %>%
594
+ formatStyle("Stuff+", backgroundColor = styleEqual(dt$`Stuff+`, col_stuff)) %>%
595
+ formatStyle("Location+", backgroundColor = styleEqual(dt$`Location+`, col_loc)) %>%
596
+ formatStyle("ERA", backgroundColor = styleEqual(dt$ERA, col_era)) %>%
597
+ formatStyle("FIP", backgroundColor = styleEqual(dt$FIP, col_fip)) %>%
598
+ formatStyle("WHIP", backgroundColor = styleEqual(dt$WHIP, col_whip)) %>%
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
599
  formatStyle("Portal",
600
  color = styleEqual(c("Yes","No"), c("#00840D","#aaaaaa")),
601
  fontWeight = styleEqual(c("Yes","No"), c("700","400"))