Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -26,7 +26,8 @@ VAA <- function(milbtotal){
|
|
| 26 |
ay))/(-sqrt((vy0*vy0)-(2*ay*(y0-(17/12))))))*(180/pi))
|
| 27 |
}
|
| 28 |
pitcher_summary <- function(game_pk,date){
|
| 29 |
-
|
|
|
|
| 30 |
tmilb <- mlb_pbp(game_pk)
|
| 31 |
tmilb <- tmilb |>
|
| 32 |
filter(type == "pitch")
|
|
@@ -51,9 +52,9 @@ pitcher_summary <- function(game_pk,date){
|
|
| 51 |
tmilb <- tmilb |>
|
| 52 |
mutate(is_strike_swinging = ifelse(description == "Swinging Strike" |
|
| 53 |
description == "Foul Tip",TRUE,FALSE))
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
|
| 58 |
}
|
| 59 |
break_plot <- function(game){
|
|
@@ -101,13 +102,13 @@ summary_table <- function(game){
|
|
| 101 |
description == "Swinging Strike" |
|
| 102 |
description == "Swinging Strike (Blocked)",1,0))|>
|
| 103 |
mutate(swing = ifelse(description == "Foul" |
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
mutate(is_strike_swinging = ifelse(is_strike_swinging == TRUE,1,0)) |>
|
| 112 |
mutate(Pitch = pitch_name) |>
|
| 113 |
group_by(Pitch)|>
|
|
@@ -246,8 +247,8 @@ ui <- grid_page(
|
|
| 246 |
|
| 247 |
|
| 248 |
server <- function(input, output) {
|
| 249 |
-
game <- reactive(pitcher_summary(input$game_pk))
|
| 250 |
-
id <- reactive(as.character(game()[1,4]))
|
| 251 |
observeEvent(input$level,{
|
| 252 |
if(input$level == "AAA"){
|
| 253 |
updateSelectizeInput(session = getDefaultReactiveDomain(),"homeT","Home Team:",choices = aaateamH[,1])
|
|
@@ -268,13 +269,13 @@ server <- function(input, output) {
|
|
| 268 |
})
|
| 269 |
observeEvent(input$update,{
|
| 270 |
if(input$level == "AAA"){
|
| 271 |
-
pname <-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
pname <-
|
| 277 |
-
updateSelectizeInput(session = getDefaultReactiveDomain(),"pitcher","Pitcher:(For Spring Breakout if pitchers not loading, try changing game number)",choices = pname
|
| 278 |
}
|
| 279 |
if(input$level == "FSL"){
|
| 280 |
pname <- fslid |>
|
|
@@ -282,7 +283,7 @@ server <- function(input, output) {
|
|
| 282 |
filter(teams_home_team_name == input$homeT) |>
|
| 283 |
filter(teams_away_team_name == input$awayT) |>
|
| 284 |
filter(game_number == input$gamenum)
|
| 285 |
-
pname <- tryCatch({pitcher_summary(pname[,6])},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 286 |
updateSelectizeInput(session = getDefaultReactiveDomain(),"pitcher","Pitcher:(For Spring Breakout if pitchers not loading, try changing game number)",choices = pname[,3])
|
| 287 |
}
|
| 288 |
if(input$level == "MLB"){
|
|
@@ -291,30 +292,30 @@ server <- function(input, output) {
|
|
| 291 |
filter(teams_home_team_name == input$homeT) |>
|
| 292 |
filter(teams_away_team_name == input$awayT) |>
|
| 293 |
filter(game_number == input$gamenum)
|
| 294 |
-
pname <- tryCatch({pitcher_summary(pname[,6])},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 295 |
updateSelectizeInput(session = getDefaultReactiveDomain(),"pitcher","Pitcher:(For Spring Breakout if pitchers not loading, try changing game number)",choices = pname[,3])
|
| 296 |
}
|
| 297 |
if(input$level == "Spring Breakout"){
|
| 298 |
-
pname <-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
pname <-
|
| 304 |
-
updateSelectizeInput(session = getDefaultReactiveDomain(),"pitcher","Pitcher:(For Spring Breakout if pitchers not loading, try changing game number)",choices = pname
|
| 305 |
}
|
| 306 |
})
|
| 307 |
observeEvent(input$update1,{
|
| 308 |
if(input$level == "MLB"){
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
}
|
| 319 |
if(input$level == "FSL"){
|
| 320 |
id <- fslid |>
|
|
@@ -322,7 +323,7 @@ server <- function(input, output) {
|
|
| 322 |
filter(teams_home_team_name == input$homeT) |>
|
| 323 |
filter(teams_away_team_name == input$awayT) |>
|
| 324 |
filter(game_number == input$gamenum)
|
| 325 |
-
game <- tryCatch({pitcher_summary(id[,6])},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 326 |
game <- game |>
|
| 327 |
filter(`Pitcher Name` == input$pitcher)
|
| 328 |
id <- as.character(game[1,4])
|
|
@@ -333,7 +334,7 @@ server <- function(input, output) {
|
|
| 333 |
filter(teams_home_team_name == input$homeT) |>
|
| 334 |
filter(teams_away_team_name == input$awayT) |>
|
| 335 |
filter(game_number == input$gamenum)
|
| 336 |
-
game <- tryCatch({pitcher_summary(id[,6])},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 337 |
game <- game |>
|
| 338 |
filter(`Pitcher Name` == input$pitcher)
|
| 339 |
id <- as.character(game[1,4])
|
|
@@ -344,41 +345,41 @@ server <- function(input, output) {
|
|
| 344 |
filter(teams_home_team_name == input$homeT) |>
|
| 345 |
filter(teams_away_team_name == input$awayT) |>
|
| 346 |
filter(game_number == input$gamenum)
|
| 347 |
-
game <- tryCatch({pitcher_summary(id[,6])},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 348 |
game <- game |>
|
| 349 |
filter(`Pitcher Name` == input$pitcher)
|
| 350 |
id <- as.character(game[1,4])
|
| 351 |
}
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
)
|
| 376 |
-
}
|
| 377 |
-
output$cardTitle <- renderText(
|
| 378 |
-
title <- paste(input$title,"Made by @TimStats", sep = " ")
|
| 379 |
-
)
|
| 380 |
-
})
|
| 381 |
}
|
| 382 |
|
| 383 |
|
| 384 |
-
shinyApp(ui, server)
|
|
|
|
| 26 |
ay))/(-sqrt((vy0*vy0)-(2*ay*(y0-(17/12))))))*(180/pi))
|
| 27 |
}
|
| 28 |
pitcher_summary <- function(game_pk,date){
|
| 29 |
+
gdate <- as.Date.character(date)
|
| 30 |
+
gdate <- as.Date(gdate)
|
| 31 |
tmilb <- mlb_pbp(game_pk)
|
| 32 |
tmilb <- tmilb |>
|
| 33 |
filter(type == "pitch")
|
|
|
|
| 52 |
tmilb <- tmilb |>
|
| 53 |
mutate(is_strike_swinging = ifelse(description == "Swinging Strike" |
|
| 54 |
description == "Foul Tip",TRUE,FALSE))
|
| 55 |
+
tmilb <- tmilb |>
|
| 56 |
+
mutate(date = gdate)
|
| 57 |
+
return(tmilb)
|
| 58 |
|
| 59 |
}
|
| 60 |
break_plot <- function(game){
|
|
|
|
| 102 |
description == "Swinging Strike" |
|
| 103 |
description == "Swinging Strike (Blocked)",1,0))|>
|
| 104 |
mutate(swing = ifelse(description == "Foul" |
|
| 105 |
+
description == "Foul Pitchout" |
|
| 106 |
+
description == "In play, no out" |
|
| 107 |
+
description == "In play, out(s)" |
|
| 108 |
+
description == "In play, run(s)" |
|
| 109 |
+
description == "Swinging Strike" |
|
| 110 |
+
description == "swinging Strike (Blocked)" |
|
| 111 |
+
description == "Foul Tip",1,0)) |>
|
| 112 |
mutate(is_strike_swinging = ifelse(is_strike_swinging == TRUE,1,0)) |>
|
| 113 |
mutate(Pitch = pitch_name) |>
|
| 114 |
group_by(Pitch)|>
|
|
|
|
| 247 |
|
| 248 |
|
| 249 |
server <- function(input, output) {
|
| 250 |
+
# game <- reactive(pitcher_summary(input$game_pk))
|
| 251 |
+
# id <- reactive(as.character(game()[1,4]))
|
| 252 |
observeEvent(input$level,{
|
| 253 |
if(input$level == "AAA"){
|
| 254 |
updateSelectizeInput(session = getDefaultReactiveDomain(),"homeT","Home Team:",choices = aaateamH[,1])
|
|
|
|
| 269 |
})
|
| 270 |
observeEvent(input$update,{
|
| 271 |
if(input$level == "AAA"){
|
| 272 |
+
pname <- aaaid |>
|
| 273 |
+
filter(date == input$date) |>
|
| 274 |
+
filter(teams_home_team_name == input$homeT) |>
|
| 275 |
+
filter(teams_away_team_name == input$awayT) |>
|
| 276 |
+
filter(game_number == input$gamenum)
|
| 277 |
+
pname <- tryCatch({pitcher_summary(pname[,6],input$date)},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 278 |
+
updateSelectizeInput(session = getDefaultReactiveDomain(),"pitcher","Pitcher:(For Spring Breakout if pitchers not loading, try changing game number)",choices = pname[,3])
|
| 279 |
}
|
| 280 |
if(input$level == "FSL"){
|
| 281 |
pname <- fslid |>
|
|
|
|
| 283 |
filter(teams_home_team_name == input$homeT) |>
|
| 284 |
filter(teams_away_team_name == input$awayT) |>
|
| 285 |
filter(game_number == input$gamenum)
|
| 286 |
+
pname <- tryCatch({pitcher_summary(pname[,6],input$date)},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 287 |
updateSelectizeInput(session = getDefaultReactiveDomain(),"pitcher","Pitcher:(For Spring Breakout if pitchers not loading, try changing game number)",choices = pname[,3])
|
| 288 |
}
|
| 289 |
if(input$level == "MLB"){
|
|
|
|
| 292 |
filter(teams_home_team_name == input$homeT) |>
|
| 293 |
filter(teams_away_team_name == input$awayT) |>
|
| 294 |
filter(game_number == input$gamenum)
|
| 295 |
+
pname <- tryCatch({pitcher_summary(pname[,6],input$date)},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 296 |
updateSelectizeInput(session = getDefaultReactiveDomain(),"pitcher","Pitcher:(For Spring Breakout if pitchers not loading, try changing game number)",choices = pname[,3])
|
| 297 |
}
|
| 298 |
if(input$level == "Spring Breakout"){
|
| 299 |
+
pname <- sbid |>
|
| 300 |
+
filter(date == input$date) |>
|
| 301 |
+
filter(teams_home_team_name == input$homeT) |>
|
| 302 |
+
filter(teams_away_team_name == input$awayT) |>
|
| 303 |
+
filter(game_number == input$gamenum)
|
| 304 |
+
pname <- tryCatch({pitcher_summary(pname[,6],input$date)},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 305 |
+
updateSelectizeInput(session = getDefaultReactiveDomain(),"pitcher","Pitcher:(For Spring Breakout if pitchers not loading, try changing game number)",choices = pname[,3])
|
| 306 |
}
|
| 307 |
})
|
| 308 |
observeEvent(input$update1,{
|
| 309 |
if(input$level == "MLB"){
|
| 310 |
+
id <- mlbid |>
|
| 311 |
+
filter(date == as.character.Date(input$date)) |>
|
| 312 |
+
filter(teams_home_team_name == input$homeT) |>
|
| 313 |
+
filter(teams_away_team_name == input$awayT) |>
|
| 314 |
+
filter(game_number == input$gamenum)
|
| 315 |
+
game <- tryCatch({pitcher_summary(id[,6],input$date)},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 316 |
+
game <- game |>
|
| 317 |
+
filter(`Pitcher Name` == input$pitcher)
|
| 318 |
+
id <- as.character(game[1,4])
|
| 319 |
}
|
| 320 |
if(input$level == "FSL"){
|
| 321 |
id <- fslid |>
|
|
|
|
| 323 |
filter(teams_home_team_name == input$homeT) |>
|
| 324 |
filter(teams_away_team_name == input$awayT) |>
|
| 325 |
filter(game_number == input$gamenum)
|
| 326 |
+
game <- tryCatch({pitcher_summary(id[,6],input$date)},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 327 |
game <- game |>
|
| 328 |
filter(`Pitcher Name` == input$pitcher)
|
| 329 |
id <- as.character(game[1,4])
|
|
|
|
| 334 |
filter(teams_home_team_name == input$homeT) |>
|
| 335 |
filter(teams_away_team_name == input$awayT) |>
|
| 336 |
filter(game_number == input$gamenum)
|
| 337 |
+
game <- tryCatch({pitcher_summary(id[,6],input$date)},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 338 |
game <- game |>
|
| 339 |
filter(`Pitcher Name` == input$pitcher)
|
| 340 |
id <- as.character(game[1,4])
|
|
|
|
| 345 |
filter(teams_home_team_name == input$homeT) |>
|
| 346 |
filter(teams_away_team_name == input$awayT) |>
|
| 347 |
filter(game_number == input$gamenum)
|
| 348 |
+
game <- tryCatch({pitcher_summary(id[,6],input$date)},error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
|
| 349 |
game <- game |>
|
| 350 |
filter(`Pitcher Name` == input$pitcher)
|
| 351 |
id <- as.character(game[1,4])
|
| 352 |
}
|
| 353 |
+
output$breakgraph <- renderPlot({
|
| 354 |
+
break_plot(game)
|
| 355 |
+
})
|
| 356 |
+
|
| 357 |
+
output$strikezone <- renderPlot({
|
| 358 |
+
pitch_plot(game)
|
| 359 |
+
})
|
| 360 |
+
|
| 361 |
+
output$myTable <- renderTable({
|
| 362 |
+
t <- summary_table(game)
|
| 363 |
+
return(t)
|
| 364 |
+
},width = '1150px',digits = 1,na = "NA",align = 'c')
|
| 365 |
+
output$picture <- renderImage({
|
| 366 |
+
if(input$league == "MLB"){
|
| 367 |
+
y <- paste("https://midfield.mlbstatic.com/v1/people/","/mlb/300?circle=false",sep = id)
|
| 368 |
+
}
|
| 369 |
+
if(input$league == "MiLB"){
|
| 370 |
+
y <- paste("https://midfield.mlbstatic.com/v1/people/","/milb/300?circle=false",sep = id)
|
| 371 |
+
}
|
| 372 |
+
photo <- tempfile()
|
| 373 |
+
download.file(y,photo,mode = 'wb')
|
| 374 |
+
list(
|
| 375 |
+
src = photo
|
| 376 |
+
)
|
| 377 |
+
},deleteFile = TRUE)
|
| 378 |
+
output$cardTitle <- renderText(
|
| 379 |
+
title <- paste(input$title,"Made by @TimStats", sep = " ")
|
| 380 |
)
|
| 381 |
+
})
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
}
|
| 383 |
|
| 384 |
|
| 385 |
+
shinyApp(ui, server)
|