Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -165,25 +165,22 @@ 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 |
-
return(milb_url)
|
| 182 |
-
}
|
| 183 |
-
}, error = function(e) NULL)
|
| 184 |
|
| 185 |
-
#
|
| 186 |
-
return(
|
| 187 |
}
|
| 188 |
|
| 189 |
get_player_info <- function(player_id, season, level = "MLB") {
|
|
|
|
| 165 |
}
|
| 166 |
|
| 167 |
get_player_image <- function(player_id) {
|
| 168 |
+
# Try MLB silo image first
|
| 169 |
+
silo_url <- sprintf("https://img.mlbstatic.com/mlb-photos/image/upload/w_200,q_auto:best/v1/people/%s/headshot/silo/current", player_id)
|
| 170 |
|
| 171 |
+
# Check if silo works
|
| 172 |
+
silo_result <- tryCatch({
|
| 173 |
+
response <- httr::HEAD(silo_url)
|
| 174 |
+
httr::status_code(response) == 200
|
| 175 |
+
}, error = function(e) FALSE)
|
| 176 |
+
|
| 177 |
+
# If silo fails, use MiLB with correct formatting
|
| 178 |
+
if (!silo_result) {
|
| 179 |
+
return(sprintf("https://img.mlbstatic.com/mlb-photos/image/upload/c_fill,g_auto,b_white,ar_1:1/w_180/v1/people/%s/headshot/milb/current", player_id))
|
| 180 |
+
}
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
+
# Return silo if it worked
|
| 183 |
+
return(silo_url)
|
| 184 |
}
|
| 185 |
|
| 186 |
get_player_info <- function(player_id, season, level = "MLB") {
|