TimStats commited on
Commit
bcbb6ca
·
verified ·
1 Parent(s): b440147

Update app.R

Browse files
Files changed (1) hide show
  1. app.R +20 -2
app.R CHANGED
@@ -150,6 +150,21 @@ get_team_logo <- function(team_name) {
150
  }
151
  }
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  download_and_process_image <- function(url) {
154
  tryCatch({
155
  response <- GET(url)
@@ -779,14 +794,17 @@ server <- function(input, output, session) {
779
  pitcher_team <- NULL
780
  if(paste0("ID", pitcher_id) %in% names(bs$teams$away$players)) {
781
  pitcher_team <- bs$teams$away$team$name
 
782
  } else if(paste0("ID", pitcher_id) %in% names(bs$teams$home$players)) {
783
  pitcher_team <- bs$teams$home$team$name
 
784
  }
785
 
786
- if(is.null(pitcher_team)) {
787
  mlb_team_logo <- textGrob("Logo not available", gp = gpar(col = "gray", fontsize = 12))
788
  } else {
789
- mlb_team_logo <- get_team_logo(pitcher_team)
 
790
  if(is.null(mlb_team_logo)) {
791
  mlb_team_logo <- textGrob("Logo not available", gp = gpar(col = "gray", fontsize = 12))
792
  }
 
150
  }
151
  }
152
 
153
+ logo_svg <- function(id){
154
+ logo_url <- paste0("https://www.mlbstatic.com/team-logos/",id,".svg")
155
+ logo_result <- download_and_process_image(logo_url)
156
+
157
+ if (!is.null(logo_result)) {
158
+ # Set fixed size for the logo
159
+ return(rasterGrob(logo_result$img,
160
+ interpolate = TRUE,
161
+ width = unit(.75, "npc"), # Reduced size to 50% of container
162
+ height = unit(.75, "npc")))
163
+ } else {
164
+ return(textGrob("Logo not available", gp = gpar(col = "gray", fontsize = 12)))
165
+ }
166
+ }
167
+
168
  download_and_process_image <- function(url) {
169
  tryCatch({
170
  response <- GET(url)
 
794
  pitcher_team <- NULL
795
  if(paste0("ID", pitcher_id) %in% names(bs$teams$away$players)) {
796
  pitcher_team <- bs$teams$away$team$name
797
+ pitcher_id <- bs$teams$away$team$id
798
  } else if(paste0("ID", pitcher_id) %in% names(bs$teams$home$players)) {
799
  pitcher_team <- bs$teams$home$team$name
800
+ pitcher_id <- bs$teams$home$team$id
801
  }
802
 
803
+ if(is.null(pitcher_id)) {
804
  mlb_team_logo <- textGrob("Logo not available", gp = gpar(col = "gray", fontsize = 12))
805
  } else {
806
+ #mlb_team_logo <- get_team_logo(pitcher_team)
807
+ mlb_team_logo <- logo_svg(pitcher_id)
808
  if(is.null(mlb_team_logo)) {
809
  mlb_team_logo <- textGrob("Logo not available", gp = gpar(col = "gray", fontsize = 12))
810
  }