igroffman commited on
Commit
bb254fa
·
verified ·
1 Parent(s): 281dfdd

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +23 -15
app.R CHANGED
@@ -307,7 +307,7 @@ server <- function(input, output, session){
307
  d <- pitcher_df()
308
  validate(need(nrow(d) > 0, "No data for selected pitcher"))
309
 
310
- plot_ly(
311
  data = d, source = "mv", type = "scatter", mode = "markers",
312
  x = ~HorzBreak, y = ~InducedVertBreak,
313
  text = ~paste0(
@@ -315,22 +315,26 @@ server <- function(input, output, session){
315
  "<br>Velo: ", round(RelSpeed,1), " mph",
316
  "<br>IVB: ", round(InducedVertBreak,1), " in",
317
  "<br>HB: ", round(HorzBreak,1), " in",
318
- if ("SpinRate" %in% names(d)) paste0("<br>Spin: ", round(SpinRate), " rpm") else "",
319
- "<br>UID: ", .uid
320
  ),
321
  hoverinfo = "text",
322
- customdata = ~.uid, # Use customdata for reliable key tracking
 
323
  color = ~factor(TaggedPitchType),
324
  colors = pitch_colors,
325
  marker = list(size = 10)
326
- ) |>
327
- layout(
 
328
  title = paste("Pitch Movement Chart -", input$pitcher_select),
329
  xaxis = list(title="Horizontal Break (in)", range=c(-25,25), zeroline=TRUE),
330
  yaxis = list(title="Induced Vertical Break (in)", range=c(-25,25), zeroline=TRUE),
331
  dragmode = if (input$selection_mode == "drag") "select" else "zoom"
332
- ) |>
333
- config(displaylogo = FALSE, modeBarButtonsToRemove = c("lasso2d"))
 
 
 
334
  })
335
 
336
  # Location plot
@@ -338,7 +342,7 @@ server <- function(input, output, session){
338
  d <- pitcher_df()
339
  validate(need(nrow(d) > 0, "No data for selected pitcher"))
340
 
341
- plot_ly(
342
  data = d, source = "loc",
343
  type = "scatter", mode = "markers",
344
  x = ~PlateLocSide, y = ~PlateLocHeight,
@@ -350,16 +354,17 @@ server <- function(input, output, session){
350
  "<br>Z: ", round(PlateLocHeight, 2),
351
  "<br>IVB: ", round(InducedVertBreak, 1), " in",
352
  "<br>HB: ", round(HorzBreak, 1), " in",
353
- if ("SpinRate" %in% names(d)) paste0("<br>Spin: ", round(SpinRate), " rpm") else "",
354
- "<br>UID: ", .uid
355
  ),
356
  hoverinfo = "text",
357
  customdata = ~.uid,
 
358
  color = ~factor(TaggedPitchType),
359
  colors = pitch_colors,
360
  marker = list(size = 9)
361
- ) |>
362
- layout(
 
363
  title = "Pitch Location (Editable)",
364
  xaxis = list(title="Plate X (ft)", range=c(-2,2), zeroline=TRUE),
365
  yaxis = list(title="Plate Z (ft)", range=c(0,4.5), zeroline=TRUE),
@@ -371,8 +376,11 @@ server <- function(input, output, session){
371
  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",
372
  line=list(color="black", width=0.8))
373
  )
374
- ) |>
375
- config(displaylogo = FALSE, modeBarButtonsToRemove = c("lasso2d"))
 
 
 
376
  })
377
 
378
  # ---- SINGLE CLICK MODE ----
 
307
  d <- pitcher_df()
308
  validate(need(nrow(d) > 0, "No data for selected pitcher"))
309
 
310
+ p <- plot_ly(
311
  data = d, source = "mv", type = "scatter", mode = "markers",
312
  x = ~HorzBreak, y = ~InducedVertBreak,
313
  text = ~paste0(
 
315
  "<br>Velo: ", round(RelSpeed,1), " mph",
316
  "<br>IVB: ", round(InducedVertBreak,1), " in",
317
  "<br>HB: ", round(HorzBreak,1), " in",
318
+ if ("SpinRate" %in% names(d)) paste0("<br>Spin: ", round(SpinRate), " rpm") else ""
 
319
  ),
320
  hoverinfo = "text",
321
+ customdata = ~.uid,
322
+ key = ~.uid, # Keep key for tracking
323
  color = ~factor(TaggedPitchType),
324
  colors = pitch_colors,
325
  marker = list(size = 10)
326
+ )
327
+
328
+ p <- p %>% layout(
329
  title = paste("Pitch Movement Chart -", input$pitcher_select),
330
  xaxis = list(title="Horizontal Break (in)", range=c(-25,25), zeroline=TRUE),
331
  yaxis = list(title="Induced Vertical Break (in)", range=c(-25,25), zeroline=TRUE),
332
  dragmode = if (input$selection_mode == "drag") "select" else "zoom"
333
+ )
334
+
335
+ p <- p %>% config(displaylogo = FALSE, modeBarButtonsToRemove = c("lasso2d"))
336
+
337
+ p
338
  })
339
 
340
  # Location plot
 
342
  d <- pitcher_df()
343
  validate(need(nrow(d) > 0, "No data for selected pitcher"))
344
 
345
+ p <- plot_ly(
346
  data = d, source = "loc",
347
  type = "scatter", mode = "markers",
348
  x = ~PlateLocSide, y = ~PlateLocHeight,
 
354
  "<br>Z: ", round(PlateLocHeight, 2),
355
  "<br>IVB: ", round(InducedVertBreak, 1), " in",
356
  "<br>HB: ", round(HorzBreak, 1), " in",
357
+ if ("SpinRate" %in% names(d)) paste0("<br>Spin: ", round(SpinRate), " rpm") else ""
 
358
  ),
359
  hoverinfo = "text",
360
  customdata = ~.uid,
361
+ key = ~.uid,
362
  color = ~factor(TaggedPitchType),
363
  colors = pitch_colors,
364
  marker = list(size = 9)
365
+ )
366
+
367
+ p <- p %>% layout(
368
  title = "Pitch Location (Editable)",
369
  xaxis = list(title="Plate X (ft)", range=c(-2,2), zeroline=TRUE),
370
  yaxis = list(title="Plate Z (ft)", range=c(0,4.5), zeroline=TRUE),
 
376
  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",
377
  line=list(color="black", width=0.8))
378
  )
379
+ )
380
+
381
+ p <- p %>% config(displaylogo = FALSE, modeBarButtonsToRemove = c("lasso2d"))
382
+
383
+ p
384
  })
385
 
386
  # ---- SINGLE CLICK MODE ----