Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -778,12 +778,16 @@ server <- function(input, output, session) {
|
|
| 778 |
TaggedPitchType %in% c("OneSeamFastBall", "TwoSeamFastBall", "Sinker", "Two-Seam", "One-Seam") ~ "Sinker",
|
| 779 |
TaggedPitchType %in% c("ChangeUp", "Changeup") ~ "Changeup",
|
| 780 |
TRUE ~ TaggedPitchType
|
| 781 |
-
)
|
|
|
|
|
|
|
| 782 |
# Create necessary indicator variables if they don't exist
|
| 783 |
in_zone = if ("StrikeZoneIndicator" %in% names(.)) StrikeZoneIndicator else
|
| 784 |
ifelse(!is.na(PlateLocSide) & !is.na(PlateLocHeight) &
|
| 785 |
PlateLocSide >= -0.95 & PlateLocSide <= 0.95 &
|
| 786 |
PlateLocHeight >= 1.6 & PlateLocHeight <= 3.5, 1, 0),
|
|
|
|
|
|
|
| 787 |
is_whiff = if ("WhiffIndicator" %in% names(.)) WhiffIndicator else
|
| 788 |
ifelse(!is.na(PitchCall) & PitchCall == "StrikeSwinging", 1, 0),
|
| 789 |
chase = if ("Chaseindicator" %in% names(.)) Chaseindicator else
|
|
@@ -809,7 +813,7 @@ server <- function(input, output, session) {
|
|
| 809 |
`Avg Spin` = if ("SpinRate" %in% names(.)) sprintf("%.0f rpm", mean(SpinRate, na.rm = TRUE)) else "—",
|
| 810 |
`Rel Height` = if ("RelHeight" %in% names(.)) sprintf("%.1f", mean(RelHeight, na.rm = TRUE)) else "—",
|
| 811 |
`Zone%` = sprintf("%.1f%%", round(mean(in_zone, na.rm = TRUE) * 100, 1)),
|
| 812 |
-
`Whiff%` = sprintf("%.1f%%", round(
|
| 813 |
`Chase%` = sprintf("%.1f%%", round(mean(chase, na.rm = TRUE) * 100, 1)),
|
| 814 |
.groups = "drop"
|
| 815 |
) %>%
|
|
@@ -829,6 +833,9 @@ server <- function(input, output, session) {
|
|
| 829 |
|
| 830 |
info_text <- paste(
|
| 831 |
paste("Pitcher:", pitch_info$pitcher),
|
|
|
|
|
|
|
|
|
|
| 832 |
paste("Current Type:", pitch_data$TaggedPitchType),
|
| 833 |
paste("Velocity:", round(pitch_data$RelSpeed, 1), "mph"),
|
| 834 |
paste("Horizontal Break:", round(pitch_data$HorzBreak, 1), "inches"),
|
|
@@ -952,6 +959,5 @@ server <- function(input, output, session) {
|
|
| 952 |
}
|
| 953 |
)
|
| 954 |
}
|
| 955 |
-
|
| 956 |
-
# Run the app
|
| 957 |
shinyApp(ui = ui, server = server)
|
|
|
|
| 778 |
TaggedPitchType %in% c("OneSeamFastBall", "TwoSeamFastBall", "Sinker", "Two-Seam", "One-Seam") ~ "Sinker",
|
| 779 |
TaggedPitchType %in% c("ChangeUp", "Changeup") ~ "Changeup",
|
| 780 |
TRUE ~ TaggedPitchType
|
| 781 |
+
)
|
| 782 |
+
) %>%
|
| 783 |
+
mutate(
|
| 784 |
# Create necessary indicator variables if they don't exist
|
| 785 |
in_zone = if ("StrikeZoneIndicator" %in% names(.)) StrikeZoneIndicator else
|
| 786 |
ifelse(!is.na(PlateLocSide) & !is.na(PlateLocHeight) &
|
| 787 |
PlateLocSide >= -0.95 & PlateLocSide <= 0.95 &
|
| 788 |
PlateLocHeight >= 1.6 & PlateLocHeight <= 3.5, 1, 0),
|
| 789 |
+
is_swing = ifelse(!is.na(PitchCall) &
|
| 790 |
+
PitchCall %in% c("StrikeSwinging", "FoulBall", "FoulBallNotFieldable", "FoulBallFieldable", "InPlay"), 1, 0),
|
| 791 |
is_whiff = if ("WhiffIndicator" %in% names(.)) WhiffIndicator else
|
| 792 |
ifelse(!is.na(PitchCall) & PitchCall == "StrikeSwinging", 1, 0),
|
| 793 |
chase = if ("Chaseindicator" %in% names(.)) Chaseindicator else
|
|
|
|
| 813 |
`Avg Spin` = if ("SpinRate" %in% names(.)) sprintf("%.0f rpm", mean(SpinRate, na.rm = TRUE)) else "—",
|
| 814 |
`Rel Height` = if ("RelHeight" %in% names(.)) sprintf("%.1f", mean(RelHeight, na.rm = TRUE)) else "—",
|
| 815 |
`Zone%` = sprintf("%.1f%%", round(mean(in_zone, na.rm = TRUE) * 100, 1)),
|
| 816 |
+
`Whiff%` = sprintf("%.1f%%", round(sum(is_whiff, na.rm = TRUE) / sum(is_swing, na.rm = TRUE) * 100, 1)),
|
| 817 |
`Chase%` = sprintf("%.1f%%", round(mean(chase, na.rm = TRUE) * 100, 1)),
|
| 818 |
.groups = "drop"
|
| 819 |
) %>%
|
|
|
|
| 833 |
|
| 834 |
info_text <- paste(
|
| 835 |
paste("Pitcher:", pitch_info$pitcher),
|
| 836 |
+
if ("PitchNo" %in% names(pitch_data) && !is.na(pitch_data$PitchNo)) {
|
| 837 |
+
paste("Pitch Number:", pitch_data$PitchNo)
|
| 838 |
+
} else "",
|
| 839 |
paste("Current Type:", pitch_data$TaggedPitchType),
|
| 840 |
paste("Velocity:", round(pitch_data$RelSpeed, 1), "mph"),
|
| 841 |
paste("Horizontal Break:", round(pitch_data$HorzBreak, 1), "inches"),
|
|
|
|
| 959 |
}
|
| 960 |
)
|
| 961 |
}
|
| 962 |
+
|
|
|
|
| 963 |
shinyApp(ui = ui, server = server)
|