Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -18,6 +18,7 @@ library(grid)
|
|
| 18 |
library(gridExtra)
|
| 19 |
library(png)
|
| 20 |
library(xgboost)
|
|
|
|
| 21 |
pdf(file = NULL)
|
| 22 |
Sys.setenv(TZ='EST')
|
| 23 |
|
|
@@ -309,7 +310,7 @@ ui <- fluidPage(
|
|
| 309 |
actionButton("update", "Find Pitcher", icon("magnifying-glass"),
|
| 310 |
style = "color: #FFFFFF; background-color: #0077B6; width: 100%;"),
|
| 311 |
selectizeInput("pitcher", "Pitcher Name:", c(" ")),
|
| 312 |
-
|
| 313 |
textInput("title", "Card Title"),
|
| 314 |
actionButton("update1", "Make Card", icon("plus"),
|
| 315 |
style = "color: #FFFFFF; background-color: #0077B6; width: 100%;"),
|
|
@@ -453,11 +454,39 @@ server <- function(input, output, session) {
|
|
| 453 |
grid.newpage()
|
| 454 |
grid.draw(table_plot)
|
| 455 |
# Download and process image
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
|
| 462 |
photo <- tempfile()
|
| 463 |
download.file(y, photo, mode = 'wb')
|
|
@@ -484,7 +513,7 @@ server <- function(input, output, session) {
|
|
| 484 |
paste("baseball_card_", Sys.Date(), ".png", sep = "")
|
| 485 |
},
|
| 486 |
content = function(file) {
|
| 487 |
-
ggsave(file, plot = combinedPlot(), width =
|
| 488 |
}
|
| 489 |
)
|
| 490 |
}
|
|
|
|
| 18 |
library(gridExtra)
|
| 19 |
library(png)
|
| 20 |
library(xgboost)
|
| 21 |
+
library(httr)
|
| 22 |
pdf(file = NULL)
|
| 23 |
Sys.setenv(TZ='EST')
|
| 24 |
|
|
|
|
| 310 |
actionButton("update", "Find Pitcher", icon("magnifying-glass"),
|
| 311 |
style = "color: #FFFFFF; background-color: #0077B6; width: 100%;"),
|
| 312 |
selectizeInput("pitcher", "Pitcher Name:", c(" ")),
|
| 313 |
+
# selectizeInput("league", "MLB or MiLB Photo", c("MLB", "MiLB")),
|
| 314 |
textInput("title", "Card Title"),
|
| 315 |
actionButton("update1", "Make Card", icon("plus"),
|
| 316 |
style = "color: #FFFFFF; background-color: #0077B6; width: 100%;"),
|
|
|
|
| 454 |
grid.newpage()
|
| 455 |
grid.draw(table_plot)
|
| 456 |
# Download and process image
|
| 457 |
+
# if(input$league == "MLB"){
|
| 458 |
+
# y <- paste("https://midfield.mlbstatic.com/v1/people/","/mlb/300?circle=false",sep = id)
|
| 459 |
+
# } else {
|
| 460 |
+
# y <- paste("https://midfield.mlbstatic.com/v1/people/","/milb/300?circle=false",sep = id)
|
| 461 |
+
# }
|
| 462 |
+
#if (input$league == "MLB") {
|
| 463 |
+
y <- paste0("https://midfield.mlbstatic.com/v1/people/", id, "/mlb/300?circle=false")
|
| 464 |
+
# } else {
|
| 465 |
+
# y <- paste0("https://midfield.mlbstatic.com/v1/people/", id, "/milb/300?circle=false")
|
| 466 |
+
# }
|
| 467 |
+
|
| 468 |
+
# Initialize the URL to NULL
|
| 469 |
+
y <- NULL
|
| 470 |
+
|
| 471 |
+
# Try the MLB URL first
|
| 472 |
+
mlb_url <- paste0("https://midfield.mlbstatic.com/v1/people/", id, "/mlb/300?circle=false")
|
| 473 |
+
response <- httr::GET(mlb_url)
|
| 474 |
+
|
| 475 |
+
if (httr::status_code(response) == 200) {
|
| 476 |
+
y <- mlb_url # Use MLB URL if it returns a 200 status code
|
| 477 |
+
} else if (httr::status_code(response) == 404) {
|
| 478 |
+
# If MLB URL fails with a 404, try the MiLB URL
|
| 479 |
+
milb_url <- paste0("https://midfield.mlbstatic.com/v1/people/", id, "/milb/300?circle=false")
|
| 480 |
+
response <- httr::GET(milb_url)
|
| 481 |
+
|
| 482 |
+
if (httr::status_code(response) == 200) {
|
| 483 |
+
y <- milb_url # Use MiLB URL if it returns a 200 status code
|
| 484 |
+
} else {
|
| 485 |
+
stop("Both MLB and MiLB URLs failed with 404 error")
|
| 486 |
+
}
|
| 487 |
+
} else {
|
| 488 |
+
stop("MLB URL failed with an unexpected error")
|
| 489 |
+
}
|
| 490 |
|
| 491 |
photo <- tempfile()
|
| 492 |
download.file(y, photo, mode = 'wb')
|
|
|
|
| 513 |
paste("baseball_card_", Sys.Date(), ".png", sep = "")
|
| 514 |
},
|
| 515 |
content = function(file) {
|
| 516 |
+
ggsave(file, plot = combinedPlot(), width = 18, height = 12, dpi = 300)
|
| 517 |
}
|
| 518 |
)
|
| 519 |
}
|