From 4733fd3cb56e83fa69e0c3ea72b84cbe0b9efd15 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Mon, 21 Jun 2021 15:42:00 +0200 Subject: [PATCH] downloading table --- finance.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/finance.py b/finance.py index 357dec4..a9226e2 100755 --- a/finance.py +++ b/finance.py @@ -4,7 +4,7 @@ import dash_core_components as dcc import dash_table import plotly.express as px import yfinance as yf -from dash.dependencies import Input, Output +from dash.dependencies import Input, Output, State import plotly.graph_objects as go import numpy as np import pandas as pd @@ -111,12 +111,15 @@ app.layout = html.Div( html.Div( className='div-for-dropdown', children=[ - dcc.Dropdown(id='table_selector', + dcc.Dropdown(id='table_selector', options=get_options(stock_list), multi=False, value=selected_stock_in_table, style={'backgroundColor': '#1E1E1E'}, className='stockselector' - ) + ), + html.Button("Pobierz dane", id="btn_data"), + dcc.Download(id="download-data") + ], style={'color': '#1E1E1E'}), html.P('Wybierz przedział czasu by policzyć średnie i wachania'), @@ -147,6 +150,14 @@ app.layout = html.Div( ] ) +@app.callback( + Output("download-data", "data"), + Input("btn_data", "n_clicks"), + prevent_initial_call=True, +) +def create_download_file(n_clicks): + global selected_stock_in_table_df + return dcc.send_data_frame(selected_stock_in_table_df.to_csv, "data.csv") # Callback for timeseries price @app.callback(Output('timeseries', 'figure'), [Input('stockselector', 'value')])