Update app.py
Browse files
app.py
CHANGED
|
@@ -276,32 +276,17 @@ def server(input, output, session):
|
|
| 276 |
fig.subplots_adjust(left=0.01, right=0.99, top=0.99, bottom=0.01)
|
| 277 |
|
| 278 |
|
| 279 |
-
@session.download()
|
| 280 |
def download():
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
# Simulate an expensive data operation
|
| 287 |
-
game_list = scrape.get_player_games_list(sport_id = sport_id,
|
| 288 |
-
season = year_input,
|
| 289 |
-
player_id = player_input,
|
| 290 |
-
start_date = start_date,
|
| 291 |
-
end_date = end_date)
|
| 292 |
-
|
| 293 |
-
data_list = scrape.get_data(game_list_input = game_list[:])
|
| 294 |
-
df = (stuff_apply.stuff_apply(fe.feature_engineering(update.update(scrape.get_data_df(data_list = data_list).filter(
|
| 295 |
-
(pl.col("pitcher_id") == player_input)&
|
| 296 |
-
(pl.col("is_pitch") == True)&
|
| 297 |
-
(pl.col('batter_hand').is_in(split_dict_hand[input.split_id()]))
|
| 298 |
-
|
| 299 |
-
)))).with_columns(
|
| 300 |
-
pl.col('pitch_type').count().over('pitch_type').alias('pitch_count')
|
| 301 |
-
))
|
| 302 |
|
| 303 |
-
|
| 304 |
-
|
|
|
|
| 305 |
|
| 306 |
app = App(app_ui, server)
|
| 307 |
|
|
|
|
| 276 |
fig.subplots_adjust(left=0.01, right=0.99, top=0.99, bottom=0.01)
|
| 277 |
|
| 278 |
|
| 279 |
+
@session.download(filename="sample_data.csv")
|
| 280 |
def download():
|
| 281 |
+
# Create a string buffer and write the CSV to it
|
| 282 |
+
sio = StringIO()
|
| 283 |
+
cached_data().to_pandas().to_csv(sio, index=False)
|
| 284 |
+
sio.seek(0)
|
| 285 |
+
content = sio.getvalue()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
|
| 287 |
+
# Return the CSV content
|
| 288 |
+
return content
|
| 289 |
+
|
| 290 |
|
| 291 |
app = App(app_ui, server)
|
| 292 |
|