Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -140,7 +140,7 @@ build_hitter_table <- function(lb, min_pa, portal_only, bat_side, hitter_pos) {
|
|
| 140 |
df %>%
|
| 141 |
select(Name, Level, Team, Portal, Position, BatSide, `Twitter`,
|
| 142 |
HomeState, Height, Weight, PA,
|
| 143 |
-
AVG, OBP, SLG,
|
| 144 |
`IZ Whiff%`, `Chase%`, `Hard Hit%`, `Avg EV`, `GB%`, `FB%`, `LD%`) %>%
|
| 145 |
arrange(desc(PA))
|
| 146 |
}
|
|
@@ -625,6 +625,21 @@ make_color_ramp <- function(values, low, high, flip = FALSE,
|
|
| 625 |
req(stats_table(), nrow(stats_table()) > 0)
|
| 626 |
dt <- stats_table()
|
| 627 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 628 |
datatable(
|
| 629 |
dt,
|
| 630 |
rownames = FALSE,
|
|
@@ -643,7 +658,7 @@ make_color_ramp <- function(values, low, high, flip = FALSE,
|
|
| 643 |
dom = "lfrtip",
|
| 644 |
columnDefs = list(
|
| 645 |
list(className = "dt-left", targets = 0:1),
|
| 646 |
-
list(className = "dt-center", targets = 2:
|
| 647 |
list(orderable = FALSE, targets = 6)
|
| 648 |
),
|
| 649 |
initComplete = JS("function(settings, json) {
|
|
@@ -651,8 +666,26 @@ make_color_ramp <- function(values, low, high, flip = FALSE,
|
|
| 651 |
}")
|
| 652 |
)
|
| 653 |
) %>%
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 654 |
formatStyle(
|
| 655 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 656 |
color = styleEqual(c("Yes","No"), c("#00840D","#aaaaaa")),
|
| 657 |
fontWeight = styleEqual(c("Yes","No"), c("700","400"))
|
| 658 |
)
|
|
|
|
| 140 |
df %>%
|
| 141 |
select(Name, Level, Team, Portal, Position, BatSide, `Twitter`,
|
| 142 |
HomeState, Height, Weight, PA,
|
| 143 |
+
AVG, OBP, SLG, `BB%`, `K%`, `Swing%`, `Contact%`,
|
| 144 |
`IZ Whiff%`, `Chase%`, `Hard Hit%`, `Avg EV`, `GB%`, `FB%`, `LD%`) %>%
|
| 145 |
arrange(desc(PA))
|
| 146 |
}
|
|
|
|
| 625 |
req(stats_table(), nrow(stats_table()) > 0)
|
| 626 |
dt <- stats_table()
|
| 627 |
|
| 628 |
+
col_avg <- make_color_ramp(dt$AVG, 0.237, 0.347)
|
| 629 |
+
col_obp <- make_color_ramp(dt$OBP, 0.336, 0.454)
|
| 630 |
+
col_slg <- make_color_ramp(dt$SLG, 0.338, 0.600)
|
| 631 |
+
col_bb <- make_color_ramp(dt$`BB%`, 6.7, 16.0)
|
| 632 |
+
col_k <- make_color_ramp(dt$`K%`, 10.5, 26.0, flip = TRUE)
|
| 633 |
+
col_swing <- make_color_ramp(dt$`Swing%`, 36.0, 50.0)
|
| 634 |
+
col_contact <- make_color_ramp(dt$`Contact%`, 69.0, 87.0)
|
| 635 |
+
col_izwhiff <- make_color_ramp(dt$`IZ Whiff%`, 8.0, 23.0, flip = TRUE)
|
| 636 |
+
col_chase <- make_color_ramp(dt$`Chase%`, 16.0, 31.0, flip = TRUE)
|
| 637 |
+
col_hh <- make_color_ramp(dt$`Hard Hit%`, 18.0, 51.0)
|
| 638 |
+
col_ev <- make_color_ramp(dt$`Avg EV`, 80.0, 91.0)
|
| 639 |
+
col_gb <- make_color_ramp(dt$`GB%`, 31.0, 52.0, flip = TRUE)
|
| 640 |
+
col_fb <- make_color_ramp(dt$`FB%`, 20.0, 37.0)
|
| 641 |
+
col_ld <- make_color_ramp(dt$`LD%`, 17.0, 28.0)
|
| 642 |
+
|
| 643 |
datatable(
|
| 644 |
dt,
|
| 645 |
rownames = FALSE,
|
|
|
|
| 658 |
dom = "lfrtip",
|
| 659 |
columnDefs = list(
|
| 660 |
list(className = "dt-left", targets = 0:1),
|
| 661 |
+
list(className = "dt-center", targets = 2:24),
|
| 662 |
list(orderable = FALSE, targets = 6)
|
| 663 |
),
|
| 664 |
initComplete = JS("function(settings, json) {
|
|
|
|
| 666 |
}")
|
| 667 |
)
|
| 668 |
) %>%
|
| 669 |
+
formatStyle("AVG", backgroundColor = styleEqual(dt$AVG, col_avg)) %>%
|
| 670 |
+
formatStyle("OBP", backgroundColor = styleEqual(dt$OBP, col_obp)) %>%
|
| 671 |
+
formatStyle("SLG", backgroundColor = styleEqual(dt$SLG, col_slg)) %>%
|
| 672 |
+
formatStyle("BB%", backgroundColor = styleEqual(dt$`BB%`, col_bb)) %>%
|
| 673 |
+
formatStyle("K%", backgroundColor = styleEqual(dt$`K%`, col_k)) %>%
|
| 674 |
+
formatStyle("Swing%", backgroundColor = styleEqual(dt$`Swing%`, col_swing)) %>%
|
| 675 |
+
formatStyle("Contact%", backgroundColor = styleEqual(dt$`Contact%`, col_contact)) %>%
|
| 676 |
+
formatStyle("IZ Whiff%", backgroundColor = styleEqual(dt$`IZ Whiff%`, col_izwhiff)) %>%
|
| 677 |
+
formatStyle("Chase%", backgroundColor = styleEqual(dt$`Chase%`, col_chase)) %>%
|
| 678 |
+
formatStyle("Hard Hit%", backgroundColor = styleEqual(dt$`Hard Hit%`, col_hh)) %>%
|
| 679 |
+
formatStyle("Avg EV", backgroundColor = styleEqual(dt$`Avg EV`, col_ev)) %>%
|
| 680 |
+
formatStyle("GB%", backgroundColor = styleEqual(dt$`GB%`, col_gb)) %>%
|
| 681 |
+
formatStyle("FB%", backgroundColor = styleEqual(dt$`FB%`, col_fb)) %>%
|
| 682 |
+
formatStyle("LD%", backgroundColor = styleEqual(dt$`LD%`, col_ld)) %>%
|
| 683 |
formatStyle(
|
| 684 |
+
c("AVG","OBP","SLG","BB%","K%","Swing%","Contact%","IZ Whiff%",
|
| 685 |
+
"Chase%","Hard Hit%","Avg EV","GB%","FB%","LD%","PA","Height","Weight"),
|
| 686 |
+
fontWeight = "bold"
|
| 687 |
+
) %>%
|
| 688 |
+
formatStyle("Portal",
|
| 689 |
color = styleEqual(c("Yes","No"), c("#00840D","#aaaaaa")),
|
| 690 |
fontWeight = styleEqual(c("Yes","No"), c("700","400"))
|
| 691 |
)
|