Spaces:
Running
Running
Update app.R
Browse files
app.R
CHANGED
|
@@ -281,74 +281,72 @@ server <- function(input, output, session){
|
|
| 281 |
mutate(row_key = row_number())
|
| 282 |
})
|
| 283 |
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
p
|
| 351 |
-
})
|
| 352 |
|
| 353 |
# ---- Click handlers (single mode) for both plots ----
|
| 354 |
show_pitch_modal <- function(hit_row){
|
|
|
|
| 281 |
mutate(row_key = row_number())
|
| 282 |
})
|
| 283 |
|
| 284 |
+
output$movement_plot <- renderPlotly({
|
| 285 |
+
d <- pitcher_df()
|
| 286 |
+
validate(need(nrow(d) > 0, "No data for selected pitcher"))
|
| 287 |
+
|
| 288 |
+
plot_ly(
|
| 289 |
+
data = d, source = "mv", type = "scatter", mode = "markers",
|
| 290 |
+
x = ~HorzBreak, y = ~InducedVertBreak,
|
| 291 |
+
text = ~paste0(
|
| 292 |
+
"<b>", TaggedPitchType, "</b>",
|
| 293 |
+
"<br>Velo: ", round(RelSpeed,1), " mph",
|
| 294 |
+
"<br>IVB: ", round(InducedVertBreak,1), " in",
|
| 295 |
+
"<br>HB: ", round(HorzBreak,1), " in",
|
| 296 |
+
if ("SpinRate" %in% names(d)) paste0("<br>Spin: ", round(SpinRate), " rpm") else ""
|
| 297 |
+
),
|
| 298 |
+
hoverinfo = "text",
|
| 299 |
+
key = ~row_key,
|
| 300 |
+
color = ~factor(TaggedPitchType), # <-- data-driven
|
| 301 |
+
colors = pitch_colors, # <-- your palette
|
| 302 |
+
marker = list(size = 10)
|
| 303 |
+
) |>
|
| 304 |
+
layout(
|
| 305 |
+
title = paste("Pitch Movement Chart -", input$pitcher_select),
|
| 306 |
+
xaxis = list(title="Horizontal Break (in)", range=c(-25,25), zeroline=TRUE),
|
| 307 |
+
yaxis = list(title="Induced Vertical Break (in)", range=c(-25,25), zeroline=TRUE),
|
| 308 |
+
dragmode = if (input$selection_mode == "drag") "select" else "zoom"
|
| 309 |
+
) |>
|
| 310 |
+
config(displaylogo = FALSE)
|
| 311 |
+
})
|
| 312 |
+
|
| 313 |
+
output$location_plot <- renderPlotly({
|
| 314 |
+
d <- pitcher_df()
|
| 315 |
+
validate(need(nrow(d) > 0, "No data for selected pitcher"))
|
| 316 |
+
|
| 317 |
+
plot_ly(
|
| 318 |
+
data = d, source = "loc", type = "scatter", mode = "markers",
|
| 319 |
+
x = ~PlateLocSide, y = ~PlateLocHeight,
|
| 320 |
+
text = ~paste0(
|
| 321 |
+
"<b>", TaggedPitchType, "</b>",
|
| 322 |
+
"<br>Velo: ", round(RelSpeed,1), " mph",
|
| 323 |
+
"<br>X: ", round(PlateLocSide,2),
|
| 324 |
+
"<br>Z: ", round(PlateLocHeight,2),
|
| 325 |
+
"<br>IVB: ", round(InducedVertBreak,1), " in",
|
| 326 |
+
"<br>HB: ", round(HorzBreak,1), " in",
|
| 327 |
+
if ("SpinRate" %in% names(d)) paste0("<br>Spin: ", round(SpinRate), " rpm") else ""
|
| 328 |
+
),
|
| 329 |
+
hoverinfo = "text",
|
| 330 |
+
key = ~row_key,
|
| 331 |
+
color = ~factor(TaggedPitchType), # <-- data-driven
|
| 332 |
+
colors = pitch_colors, # <-- your palette
|
| 333 |
+
marker = list(size = 9)
|
| 334 |
+
) |>
|
| 335 |
+
layout(
|
| 336 |
+
title = "Pitch Location (Editable)",
|
| 337 |
+
xaxis = list(title="Plate X (ft)", range=c(-2,2), zeroline=TRUE),
|
| 338 |
+
yaxis = list(title="Plate Z (ft)", range=c(0,4.5), zeroline=TRUE),
|
| 339 |
+
dragmode = if (input$selection_mode == "drag") "select" else "zoom",
|
| 340 |
+
shapes = list(
|
| 341 |
+
list(type="rect", x0=-0.8303, x1=0.8303, y0=1.6, y1=3.5,
|
| 342 |
+
line=list(color="black", width=1), fillcolor="rgba(0,0,0,0)"),
|
| 343 |
+
list(type="path",
|
| 344 |
+
path="M -0.708 0.15 L 0.708 0.15 L 0.708 0.3 L 0 0.5 L -0.708 0.3 Z",
|
| 345 |
+
line=list(color="black", width=0.8))
|
| 346 |
+
)
|
| 347 |
+
) |>
|
| 348 |
+
config(displaylogo = FALSE)
|
| 349 |
+
})
|
|
|
|
|
|
|
| 350 |
|
| 351 |
# ---- Click handlers (single mode) for both plots ----
|
| 352 |
show_pitch_modal <- function(hit_row){
|