Spaces:
Sleeping
Sleeping
Update app.R
Browse files
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 |
-
#
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
|
| 542 |
datatable(
|
| 543 |
dt,
|
|
@@ -565,51 +581,21 @@ server <- function(input, output, session) {
|
|
| 565 |
}")
|
| 566 |
)
|
| 567 |
) %>%
|
| 568 |
-
formatStyle("FB Velo",
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
formatStyle("
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
formatStyle("
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
formatStyle("
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
formatStyle("
|
| 581 |
-
|
| 582 |
-
|
| 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"))
|