Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -73,13 +73,15 @@ load_hitter_portal <- function() {
|
|
| 73 |
names(df) <- tolower(names(df))
|
| 74 |
df %>%
|
| 75 |
rename(Batter=batter, Portal=transfer, Position=position,
|
| 76 |
-
BatSide=batside, Team=team, BA=ba, OBP=obp, SLG=slg
|
|
|
|
| 77 |
distinct(Batter, .keep_all = TRUE)
|
| 78 |
}, error = function(e) {
|
| 79 |
message("Hitter portal load failed: ", e$message)
|
| 80 |
tibble(Batter=character(), Portal=character(), Position=character(),
|
| 81 |
BatSide=character(), Team=character(),
|
| 82 |
-
BA=numeric(), OBP=numeric(), SLG=numeric()
|
|
|
|
| 83 |
})
|
| 84 |
}
|
| 85 |
|
|
@@ -187,8 +189,8 @@ build_hitter_table <- function(lb, min_pa, portal_only, bat_side, hitter_pos) {
|
|
| 187 |
df %>%
|
| 188 |
select(Name, Level, Team, Portal, Position, BatSide, `Twitter`, `Board`,
|
| 189 |
HomeState, Height, Weight, PA,
|
| 190 |
-
AVG, OBP, SLG, `BB%`, `K%`, `Swing%`, `Contact%`,
|
| 191 |
-
`Chase%`, `Hard Hit%`, `Avg EV`, `GB%`, `FB%`, `LD%`) %>%
|
| 192 |
arrange(desc(PA))
|
| 193 |
}
|
| 194 |
|
|
@@ -749,10 +751,11 @@ make_color_ramp <- function(values, low, high, flip = FALSE,
|
|
| 749 |
formatStyle("ERA", backgroundColor = styleEqual(dt$ERA, col_era)) %>%
|
| 750 |
formatStyle("FIP", backgroundColor = styleEqual(dt$FIP, col_fip)) %>%
|
| 751 |
formatStyle("WHIP", backgroundColor = styleEqual(dt$WHIP, col_whip)) %>%
|
|
|
|
|
|
|
| 752 |
formatStyle(
|
| 753 |
-
c("
|
| 754 |
-
"
|
| 755 |
-
"Pitches","Height","Weight"),
|
| 756 |
fontWeight = "bold"
|
| 757 |
) %>%
|
| 758 |
formatStyle("Portal",
|
|
@@ -780,6 +783,8 @@ make_color_ramp <- function(values, low, high, flip = FALSE,
|
|
| 780 |
col_gb <- make_color_ramp(dt$`GB%`, 31.0, 52.0, flip = TRUE)
|
| 781 |
col_fb <- make_color_ramp(dt$`FB%`, 20.0, 37.0)
|
| 782 |
col_ld <- make_color_ramp(dt$`LD%`, 17.0, 28.0)
|
|
|
|
|
|
|
| 783 |
|
| 784 |
datatable(
|
| 785 |
dt,
|
|
@@ -799,7 +804,7 @@ make_color_ramp <- function(values, low, high, flip = FALSE,
|
|
| 799 |
dom = "lfrtip",
|
| 800 |
columnDefs = list(
|
| 801 |
list(className = "dt-left", targets = 0:1),
|
| 802 |
-
list(className = "dt-center", targets = 2:
|
| 803 |
list(orderable = FALSE, targets = c(6, 7))
|
| 804 |
),
|
| 805 |
initComplete = JS("function(settings, json) {
|
|
|
|
| 73 |
names(df) <- tolower(names(df))
|
| 74 |
df %>%
|
| 75 |
rename(Batter=batter, Portal=transfer, Position=position,
|
| 76 |
+
BatSide=batside, Team=team, BA=ba, OBP=obp, SLG=slg,
|
| 77 |
+
wOBA=woba, xwOBA=xwoba) %>%
|
| 78 |
distinct(Batter, .keep_all = TRUE)
|
| 79 |
}, error = function(e) {
|
| 80 |
message("Hitter portal load failed: ", e$message)
|
| 81 |
tibble(Batter=character(), Portal=character(), Position=character(),
|
| 82 |
BatSide=character(), Team=character(),
|
| 83 |
+
BA=numeric(), OBP=numeric(), SLG=numeric(),
|
| 84 |
+
wOBA=numeric(), xwOBA=numeric())
|
| 85 |
})
|
| 86 |
}
|
| 87 |
|
|
|
|
| 189 |
df %>%
|
| 190 |
select(Name, Level, Team, Portal, Position, BatSide, `Twitter`, `Board`,
|
| 191 |
HomeState, Height, Weight, PA,
|
| 192 |
+
AVG, OBP, SLG, wOBA, xwOBA, `BB%`, `K%`, `Swing%`, `Contact%`,
|
| 193 |
+
`IZ Whiff%`, `Chase%`, `Hard Hit%`, `Avg EV`, `GB%`, `FB%`, `LD%`) %>%
|
| 194 |
arrange(desc(PA))
|
| 195 |
}
|
| 196 |
|
|
|
|
| 751 |
formatStyle("ERA", backgroundColor = styleEqual(dt$ERA, col_era)) %>%
|
| 752 |
formatStyle("FIP", backgroundColor = styleEqual(dt$FIP, col_fip)) %>%
|
| 753 |
formatStyle("WHIP", backgroundColor = styleEqual(dt$WHIP, col_whip)) %>%
|
| 754 |
+
formatStyle("wOBA", backgroundColor = styleEqual(dt$wOBA, col_woba)) %>%
|
| 755 |
+
formatStyle("xwOBA", backgroundColor = styleEqual(dt$xwOBA, col_xwoba)) %>%
|
| 756 |
formatStyle(
|
| 757 |
+
c("AVG","OBP","SLG","wOBA","xwOBA","BB%","K%","Swing%","Contact%","IZ Whiff%",
|
| 758 |
+
"Chase%","Hard Hit%","Avg EV","GB%","FB%","LD%","PA","Height","Weight"),
|
|
|
|
| 759 |
fontWeight = "bold"
|
| 760 |
) %>%
|
| 761 |
formatStyle("Portal",
|
|
|
|
| 783 |
col_gb <- make_color_ramp(dt$`GB%`, 31.0, 52.0, flip = TRUE)
|
| 784 |
col_fb <- make_color_ramp(dt$`FB%`, 20.0, 37.0)
|
| 785 |
col_ld <- make_color_ramp(dt$`LD%`, 17.0, 28.0)
|
| 786 |
+
col_woba <- make_color_ramp(dt$wOBA, 0.280, 0.420)
|
| 787 |
+
col_xwoba <- make_color_ramp(dt$xwOBA, 0.280, 0.420)
|
| 788 |
|
| 789 |
datatable(
|
| 790 |
dt,
|
|
|
|
| 804 |
dom = "lfrtip",
|
| 805 |
columnDefs = list(
|
| 806 |
list(className = "dt-left", targets = 0:1),
|
| 807 |
+
list(className = "dt-center", targets = 2:27),
|
| 808 |
list(orderable = FALSE, targets = c(6, 7))
|
| 809 |
),
|
| 810 |
initComplete = JS("function(settings, json) {
|