From 4733fd3cb56e83fa69e0c3ea72b84cbe0b9efd15 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Mon, 21 Jun 2021 15:42:00 +0200 Subject: [PATCH 1/5] 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')]) -- 2.20.1 From 48c35debc8e2cdeac8a76747971027be99195c31 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Mon, 21 Jun 2021 15:44:53 +0200 Subject: [PATCH 2/5] Added downloading selected file --- finance.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/finance.py b/finance.py index a9226e2..5c80b47 100755 --- a/finance.py +++ b/finance.py @@ -150,14 +150,15 @@ app.layout = html.Div( ] ) +# Callback for downloading file @app.callback( Output("download-data", "data"), - Input("btn_data", "n_clicks"), + [Input("btn_data", "n_clicks"), Input('table_selector', 'value')], prevent_initial_call=True, ) -def create_download_file(n_clicks): +def create_download_file(n_clicks, selected_table): global selected_stock_in_table_df - return dcc.send_data_frame(selected_stock_in_table_df.to_csv, "data.csv") + return dcc.send_data_frame(selected_stock_in_table_df.to_csv, "data-{table}.csv".format(table = selected_table)) # Callback for timeseries price @app.callback(Output('timeseries', 'figure'), [Input('stockselector', 'value')]) -- 2.20.1 From 4f5381bf41d6c3932b7df4771f75c94a502f3b8f Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Mon, 21 Jun 2021 16:00:58 +0200 Subject: [PATCH 3/5] some style fixes --- assets/style.css | 16 ++++++++++++++-- finance.py | 13 +++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/assets/style.css b/assets/style.css index 27aa47b..02cce79 100755 --- a/assets/style.css +++ b/assets/style.css @@ -245,7 +245,7 @@ a:hover { display: inline-block; height: 38px; padding: 0 30px; - color: #555; + color: #fff; text-align: center; font-size: 11px; font-weight: 600; @@ -485,7 +485,7 @@ a { padding-bottom: 12px; } .Select-control, .Select-menu-outer, .Select-multi-value-wrapper, .select-up, .is-open .Select-control { - background-color: #1E1E1E; + background-color: #1E1E1E !important; color: white; } @@ -631,4 +631,16 @@ a { /* Handle on hover */ ::-webkit-scrollbar-thumb:hover { background: #d8d8d870 !important; +} + + +/* OWN STYLES */ + +.gauges{ + display: flex; + flex-wrap: wrap; +} + +#average_gauge{ + flex-grow: 1; } \ No newline at end of file diff --git a/finance.py b/finance.py index 5c80b47..66a289b 100755 --- a/finance.py +++ b/finance.py @@ -117,14 +117,18 @@ app.layout = html.Div( style={'backgroundColor': '#1E1E1E'}, className='stockselector' ), - html.Button("Pobierz dane", id="btn_data"), + html.Button("Pobierz dane", id="btn_data",style={'margin-top': '3rem'}), dcc.Download(id="download-data") ], style={'color': '#1E1E1E'}), html.P('Wybierz przedział czasu by policzyć średnie i wachania'), - dcc.Graph(id='average_gauge'), - dcc.Graph(id='volatility_gauge'), + html.Div( + className='gauges', + children=[ + dcc.Graph(id='average_gauge'), + dcc.Graph(id='volatility_gauge') + ]), dash_table.DataTable( id='info_in_time_period', style_header={'backgroundColor': 'rgb(30, 30, 30)'}, @@ -153,7 +157,8 @@ app.layout = html.Div( # Callback for downloading file @app.callback( Output("download-data", "data"), - [Input("btn_data", "n_clicks"), Input('table_selector', 'value')], + Input("btn_data", "n_clicks"), + State('table_selector', 'value'), prevent_initial_call=True, ) def create_download_file(n_clicks, selected_table): -- 2.20.1 From 2ddca0725ce614cb8e5aecd61212c9df1bc069c8 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Mon, 21 Jun 2021 16:35:32 +0200 Subject: [PATCH 4/5] Added scatter plot --- assets/style.css | 12 ++++++++++++ finance.py | 15 ++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/assets/style.css b/assets/style.css index 02cce79..ac67f89 100755 --- a/assets/style.css +++ b/assets/style.css @@ -643,4 +643,16 @@ a { #average_gauge{ flex-grow: 1; +} + +#tab-1, #tab-2{ + background-color: #1E1E1E; + color: #fff; + border-left: none; + border-right: none; + border-bottom: none; +} + +.tab--selected{ + background-color: #111111 !important; } \ No newline at end of file diff --git a/finance.py b/finance.py index 66a289b..2296048 100755 --- a/finance.py +++ b/finance.py @@ -140,7 +140,14 @@ app.layout = html.Div( ]), html.Div(className='eight columns div-for-charts bg-grey', children=[ - dcc.Graph(id='timeseries', config={'displayModeBar': False}, animate=True), + dcc.Tabs(id='tabs', value='tab-1', children=[ + dcc.Tab(id='tab-1', label='Chart 1', value='tab-1', children=[ + dcc.Graph(id='timeseries', config={'displayModeBar': False}, animate=True), + ]), + dcc.Tab(id='tab-2', label='Chart 2', value='tab-2',children=[ + dcc.Graph(id='price-dividends', config={'displayModeBar': False}, animate=True), + ]), + ]), dash_table.DataTable( id='stock_price_table', style_header={'backgroundColor': 'rgb(30, 30, 30)'}, @@ -239,6 +246,12 @@ def change_time_period(selectedData): volatility_gauge = make_gauge('wolatylność', 0, std['Close'], 400) return average_gauge, volatility_gauge, stock_info_in_time_period_df.T.to_dict('records') +@app.callback(Output('price-dividends', 'figure'), + [Input('table_selector', 'value')]) +def update_point_chart(selected_dropdown_value): + selected_stock_in_table_df = fullTableDf.xs(selected_dropdown_value, axis=1, level=1) + figure = px.scatter(selected_stock_in_table_df, x='Volume', y='Dividends', template='plotly_dark') + return figure if __name__ == '__main__': app.run_server(debug=True) -- 2.20.1 From 7a1bcc90a1f8082d7dc1bd7151b122a7448838a6 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Mon, 21 Jun 2021 20:19:46 +0200 Subject: [PATCH 5/5] scater args fix --- finance.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/finance.py b/finance.py index 2296048..16d47df 100755 --- a/finance.py +++ b/finance.py @@ -250,7 +250,7 @@ def change_time_period(selectedData): [Input('table_selector', 'value')]) def update_point_chart(selected_dropdown_value): selected_stock_in_table_df = fullTableDf.xs(selected_dropdown_value, axis=1, level=1) - figure = px.scatter(selected_stock_in_table_df, x='Volume', y='Dividends', template='plotly_dark') + figure = px.scatter(selected_stock_in_table_df, x='Dividends', y='Close', template='plotly_dark') return figure if __name__ == '__main__': -- 2.20.1