Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -165,22 +165,25 @@ apply_percentile_calcs <- function(data) {
|
|
| 165 |
}
|
| 166 |
|
| 167 |
get_player_image <- function(player_id) {
|
| 168 |
-
#
|
| 169 |
-
|
| 170 |
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
-
#
|
| 183 |
-
return(
|
| 184 |
}
|
| 185 |
|
| 186 |
get_player_info <- function(player_id, season, level = "MLB") {
|
|
|
|
| 165 |
}
|
| 166 |
|
| 167 |
get_player_image <- function(player_id) {
|
| 168 |
+
# First try MLB format
|
| 169 |
+
mlb_url <- sprintf("https://www.mlbstatic.com/playerheadshots/mlb/player/%s.jpg", player_id)
|
| 170 |
|
| 171 |
+
result <- tryCatch({
|
| 172 |
+
response <- httr::HEAD(mlb_url)
|
| 173 |
+
if (httr::status_code(response) == 200) {
|
| 174 |
+
return(mlb_url)
|
| 175 |
+
}
|
| 176 |
+
|
| 177 |
+
# If MLB fails, try MiLB format
|
| 178 |
+
milb_url <- sprintf("https://www.mlbstatic.com/playerheadshots/milb/player/%s.jpg", player_id)
|
| 179 |
+
response <- httr::HEAD(milb_url)
|
| 180 |
+
if (httr::status_code(response) == 200) {
|
| 181 |
+
return(milb_url)
|
| 182 |
+
}
|
| 183 |
+
}, error = function(e) NULL)
|
| 184 |
|
| 185 |
+
# If both fail, return default MLB logo
|
| 186 |
+
return("https://www.mlbstatic.com/team-logos/league-on-dark/1.jpg")
|
| 187 |
}
|
| 188 |
|
| 189 |
get_player_info <- function(player_id, season, level = "MLB") {
|