Spaces:
Sleeping
Sleeping
Update app.R
Browse files
app.R
CHANGED
|
@@ -152,21 +152,48 @@ get_team_logo <- function(team_name) {
|
|
| 152 |
}
|
| 153 |
}
|
| 154 |
|
| 155 |
-
logo_svg <- function(id){
|
| 156 |
-
logo_url <- paste0("https://www.mlbstatic.com/team-logos/",id,".svg")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
logo_result <- download_and_process_image(logo_url)
|
| 158 |
|
| 159 |
if (!is.null(logo_result)) {
|
| 160 |
-
#
|
| 161 |
-
return(
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
} else {
|
| 166 |
return(textGrob("Logo not available", gp = gpar(col = "gray", fontsize = 12)))
|
| 167 |
}
|
| 168 |
}
|
| 169 |
-
|
| 170 |
download_and_process_image <- function(url) {
|
| 171 |
tryCatch({
|
| 172 |
response <- GET(url)
|
|
|
|
| 152 |
}
|
| 153 |
}
|
| 154 |
|
| 155 |
+
#logo_svg <- function(id){
|
| 156 |
+
# logo_url <- paste0("https://www.mlbstatic.com/team-logos/",id,".svg")
|
| 157 |
+
# logo_result <- download_and_process_image(logo_url)
|
| 158 |
+
#
|
| 159 |
+
# if (!is.null(logo_result)) {
|
| 160 |
+
# # Set fixed size for the logo
|
| 161 |
+
# return(rasterGrob(logo_result$img,
|
| 162 |
+
# interpolate = TRUE,
|
| 163 |
+
# width = unit(.75, "npc"), # Reduced size to 50% of container
|
| 164 |
+
# height = unit(.75, "npc")))
|
| 165 |
+
# } else {
|
| 166 |
+
# return(textGrob("Logo not available", gp = gpar(col = "gray", fontsize = 12)))
|
| 167 |
+
# }
|
| 168 |
+
#}
|
| 169 |
+
logo_svg <- function(id) {
|
| 170 |
+
logo_url <- paste0("https://www.mlbstatic.com/team-logos/", id, ".svg")
|
| 171 |
logo_result <- download_and_process_image(logo_url)
|
| 172 |
|
| 173 |
if (!is.null(logo_result)) {
|
| 174 |
+
# Create a square viewport/container first
|
| 175 |
+
return(
|
| 176 |
+
gTree(
|
| 177 |
+
children = gList(
|
| 178 |
+
# Add a transparent square background (optional)
|
| 179 |
+
rectGrob(gp = gpar(fill = NA, col = NA)),
|
| 180 |
+
# Place the logo in center of the square container
|
| 181 |
+
rasterGrob(logo_result$img,
|
| 182 |
+
interpolate = TRUE,
|
| 183 |
+
width = unit(.75, "npc"),
|
| 184 |
+
height = unit(.75, "npc"),
|
| 185 |
+
vp = viewport(width = unit(1, "snpc"),
|
| 186 |
+
height = unit(1, "snpc")))
|
| 187 |
+
),
|
| 188 |
+
vp = viewport(width = unit(1, "npc"),
|
| 189 |
+
height = unit(1, "npc"),
|
| 190 |
+
layout = grid.layout(1, 1))
|
| 191 |
+
)
|
| 192 |
+
)
|
| 193 |
} else {
|
| 194 |
return(textGrob("Logo not available", gp = gpar(col = "gray", fontsize = 12)))
|
| 195 |
}
|
| 196 |
}
|
|
|
|
| 197 |
download_and_process_image <- function(url) {
|
| 198 |
tryCatch({
|
| 199 |
response <- GET(url)
|