Update app.py
Browse files
app.py
CHANGED
|
@@ -61,6 +61,48 @@ type_dict = {'R':'Regular Season',
|
|
| 61 |
'S':'Spring',
|
| 62 |
'P':'Playoffs' }
|
| 63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
from shiny import App, reactive, ui, render
|
| 65 |
from shiny.ui import h2, tags
|
| 66 |
|
|
@@ -91,6 +133,10 @@ app_ui = ui.page_fluid(
|
|
| 91 |
ui.column(6, ui.input_select('split_id', 'Select Split', split_dict, multiple=False)),
|
| 92 |
ui.column(6, ui.input_numeric('rolling_window', 'Rolling Window (for tjStuff+ Plot)', min=1, value=50))
|
| 93 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
# Row for the action button to generate plot
|
| 96 |
ui.row(ui.input_action_button("generate_plot", "Generate Plot", class_="btn-primary")),
|
|
@@ -238,7 +284,27 @@ def server(input, output, session):
|
|
| 238 |
|
| 239 |
player_headshot(player_input=player_input, ax=ax_headshot,sport_id=sport_id,season=year_input)
|
| 240 |
player_bio(pitcher_id=player_input, ax=ax_bio,sport_id=sport_id,year_input=year_input)
|
| 241 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
|
| 243 |
stat_summary_table(df=df,
|
| 244 |
ax=ax_season_table,
|
|
|
|
| 61 |
'S':'Spring',
|
| 62 |
'P':'Playoffs' }
|
| 63 |
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# List of MLB teams and their corresponding ESPN logo URLs
|
| 67 |
+
mlb_teams = [
|
| 68 |
+
{"team": "AZ", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/ari.png&h=500&w=500"},
|
| 69 |
+
{"team": "ATL", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/atl.png&h=500&w=500"},
|
| 70 |
+
{"team": "BAL", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/bal.png&h=500&w=500"},
|
| 71 |
+
{"team": "BOS", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/bos.png&h=500&w=500"},
|
| 72 |
+
{"team": "CHC", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/chc.png&h=500&w=500"},
|
| 73 |
+
{"team": "CWS", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/chw.png&h=500&w=500"},
|
| 74 |
+
{"team": "CIN", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/cin.png&h=500&w=500"},
|
| 75 |
+
{"team": "CLE", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/cle.png&h=500&w=500"},
|
| 76 |
+
{"team": "COL", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/col.png&h=500&w=500"},
|
| 77 |
+
{"team": "DET", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/det.png&h=500&w=500"},
|
| 78 |
+
{"team": "HOU", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/hou.png&h=500&w=500"},
|
| 79 |
+
{"team": "KC", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/kc.png&h=500&w=500"},
|
| 80 |
+
{"team": "LAA", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/laa.png&h=500&w=500"},
|
| 81 |
+
{"team": "LAD", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/lad.png&h=500&w=500"},
|
| 82 |
+
{"team": "MIA", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/mia.png&h=500&w=500"},
|
| 83 |
+
{"team": "MIL", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/mil.png&h=500&w=500"},
|
| 84 |
+
{"team": "MIN", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/min.png&h=500&w=500"},
|
| 85 |
+
{"team": "NYM", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/nym.png&h=500&w=500"},
|
| 86 |
+
{"team": "NYY", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/nyy.png&h=500&w=500"},
|
| 87 |
+
{"team": "OAK", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/oak.png&h=500&w=500"},
|
| 88 |
+
{"team": "PHI", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/phi.png&h=500&w=500"},
|
| 89 |
+
{"team": "PIT", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/pit.png&h=500&w=500"},
|
| 90 |
+
{"team": "SD", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/sd.png&h=500&w=500"},
|
| 91 |
+
{"team": "SF", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/sf.png&h=500&w=500"},
|
| 92 |
+
{"team": "SEA", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/sea.png&h=500&w=500"},
|
| 93 |
+
{"team": "STL", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/stl.png&h=500&w=500"},
|
| 94 |
+
{"team": "TB", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/tb.png&h=500&w=500"},
|
| 95 |
+
{"team": "TEX", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/tex.png&h=500&w=500"},
|
| 96 |
+
{"team": "TOR", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/tor.png&h=500&w=500"},
|
| 97 |
+
{"team": "WSH", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/wsh.png&h=500&w=500"},
|
| 98 |
+
{"team": "ATH", "logo_url": "https://a.espncdn.com/combiner/i?img=/i/teamlogos/mlb/500/scoreboard/oak.png&h=500&w=500"},
|
| 99 |
+
]
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
df_image = pd.DataFrame(mlb_teams)
|
| 103 |
+
image_dict = df_image.set_index('team')['logo_url'].to_dict()
|
| 104 |
+
|
| 105 |
+
|
| 106 |
from shiny import App, reactive, ui, render
|
| 107 |
from shiny.ui import h2, tags
|
| 108 |
|
|
|
|
| 133 |
ui.column(6, ui.input_select('split_id', 'Select Split', split_dict, multiple=False)),
|
| 134 |
ui.column(6, ui.input_numeric('rolling_window', 'Rolling Window (for tjStuff+ Plot)', min=1, value=50))
|
| 135 |
),
|
| 136 |
+
ui.row(
|
| 137 |
+
ui.column(6, ui.input_switch("switch", "Custom Team?", False)),
|
| 138 |
+
ui.column(6, ui.input_select('logo_select', 'Select Custom Logo', image_dict, multiple=False))
|
| 139 |
+
),
|
| 140 |
|
| 141 |
# Row for the action button to generate plot
|
| 142 |
ui.row(ui.input_action_button("generate_plot", "Generate Plot", class_="btn-primary")),
|
|
|
|
| 284 |
|
| 285 |
player_headshot(player_input=player_input, ax=ax_headshot,sport_id=sport_id,season=year_input)
|
| 286 |
player_bio(pitcher_id=player_input, ax=ax_bio,sport_id=sport_id,year_input=year_input)
|
| 287 |
+
|
| 288 |
+
if input.switch():
|
| 289 |
+
|
| 290 |
+
# Get the logo URL from the image dictionary using the team abbreviation
|
| 291 |
+
logo_url = input.logo_select()
|
| 292 |
+
|
| 293 |
+
# Send a GET request to the logo URL
|
| 294 |
+
response = requests.get(logo_url)
|
| 295 |
+
|
| 296 |
+
# Open the image from the response content
|
| 297 |
+
img = Image.open(BytesIO(response.content))
|
| 298 |
+
|
| 299 |
+
# Display the image on the axis
|
| 300 |
+
ax.set_xlim(0, 1.3)
|
| 301 |
+
ax.set_ylim(0, 1)
|
| 302 |
+
ax.imshow(img, extent=[0.3, 1.3, 0, 1], origin='upper')
|
| 303 |
+
|
| 304 |
+
# Turn off the axis
|
| 305 |
+
ax.axis('off')
|
| 306 |
+
else:
|
| 307 |
+
plot_logo(pitcher_id=player_input, ax=ax_logo, df_team=df_teams,df_players=scrape.get_players(sport_id,year_input))
|
| 308 |
|
| 309 |
stat_summary_table(df=df,
|
| 310 |
ax=ax_season_table,
|