igroffman commited on
Commit
32dedf3
·
verified ·
1 Parent(s): fd7f280

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +27 -25
app.R CHANGED
@@ -821,32 +821,34 @@ server <- function(input, output, session) {
821
  DT::formatStyle(columns = names(summary_stats), fontSize = '12px')
822
  })
823
 
824
- # Selected pitch info in modal
825
- output$selected_pitch_info <- renderText({
826
- pitch_info <- selected_pitch()
827
- if (!is.null(pitch_info)) {
828
- pitch_data <- pitch_info$data
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"),
835
- paste("Induced Vertical Break:", round(pitch_data$InducedVertBreak, 1), "inches"),
836
- if ("SpinRate" %in% names(pitch_data) && !is.na(pitch_data$SpinRate)) {
837
- paste("Spin Rate:", round(pitch_data$SpinRate, 0), "rpm")
838
- } else "",
839
- if ("Date" %in% names(pitch_data) && !is.na(pitch_data$Date)) {
840
- paste("Date:", format(as.Date(pitch_data$Date)))
841
- } else "",
842
- sep = "\n"
843
- )
844
-
845
- return(info_text)
846
- } else {
847
- return("No pitch selected")
848
  }
849
- })
 
 
 
 
 
 
 
 
 
850
 
851
  # Update pitch type
852
  observeEvent(input$update_pitch, {
 
821
  DT::formatStyle(columns = names(summary_stats), fontSize = '12px')
822
  })
823
 
824
+ output$selected_pitch_info <- renderText({
825
+ pitch_info <- selected_pitch()
826
+ if (!is.null(pitch_info)) {
827
+ pitch_data <- pitch_info$data
828
+
829
+ # Build info text with only available fields
830
+ info_lines <- c(
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"),
835
+ paste("Induced Vertical Break:", round(pitch_data$InducedVertBreak, 1), "inches")
836
+ )
837
+
838
+ # Add optional fields only if they exist and have values
839
+ if ("SpinRate" %in% names(pitch_data) && !is.na(pitch_data$SpinRate)) {
840
+ info_lines <- c(info_lines, paste("Spin Rate:", round(pitch_data$SpinRate, 0), "rpm"))
 
 
 
 
 
 
 
841
  }
842
+
843
+ if ("Date" %in% names(pitch_data) && !is.na(pitch_data$Date)) {
844
+ info_lines <- c(info_lines, paste("Date:", pitch_data$Date))
845
+ }
846
+
847
+ return(paste(info_lines, collapse = "\n"))
848
+ } else {
849
+ return("No pitch selected")
850
+ }
851
+ })
852
 
853
  # Update pitch type
854
  observeEvent(input$update_pitch, {