table
This commit is contained in:
parent
fcfd73a040
commit
6401bcc462
48
finance.py
48
finance.py
@ -46,8 +46,11 @@ stock_list = ['WHR', 'WMB', 'WLTW', 'WYNN', 'XEL', 'XLNX', 'XYL', 'YUM', 'ZBRA',
|
|||||||
|
|
||||||
tickerData = yf.Tickers(stock_list)
|
tickerData = yf.Tickers(stock_list)
|
||||||
fullTableDf = tickerData.history(period='1d', start='2019-1-1', end='2020-1-25')
|
fullTableDf = tickerData.history(period='1d', start='2019-1-1', end='2020-1-25')
|
||||||
tickerDf = fullTableDf['Close']
|
closePrices = fullTableDf['Close']
|
||||||
|
selected_stocks_in_graph = [stock_list[0]]
|
||||||
|
selected_stocks_in_graph_df = closePrices[selected_stocks_in_graph]
|
||||||
|
selected_stock_in_table = stock_list[0]
|
||||||
|
selected_stock_in_table_df = fullTableDf.xs(selected_stock_in_table, axis=1, level=1)
|
||||||
# Initialize the app
|
# Initialize the app
|
||||||
app = dash.Dash(__name__)
|
app = dash.Dash(__name__)
|
||||||
app.config.suppress_callback_exceptions = True
|
app.config.suppress_callback_exceptions = True
|
||||||
@ -74,14 +77,14 @@ app.layout = html.Div(
|
|||||||
className='div-for-dropdown',
|
className='div-for-dropdown',
|
||||||
children=[
|
children=[
|
||||||
dcc.Dropdown(id='stockselector',
|
dcc.Dropdown(id='stockselector',
|
||||||
options=get_options(tickerDf.columns.unique()),
|
options=get_options(stock_list),
|
||||||
multi=True, value=[tickerDf.columns.sort_values()[0]],
|
multi=True, value=selected_stocks_in_graph,
|
||||||
style={'backgroundColor': '#1E1E1E'},
|
style={'backgroundColor': '#1E1E1E'},
|
||||||
className='stockselector'
|
className='stockselector'
|
||||||
),
|
),
|
||||||
dcc.Dropdown(id='table_selector',
|
dcc.Dropdown(id='table_selector',
|
||||||
options=get_options(tickerDf.columns.unique()),
|
options=get_options(stock_list),
|
||||||
multi=False, value=[tickerDf.columns.sort_values()[0]],
|
multi=False, value=selected_stock_in_table,
|
||||||
style={'backgroundColor': '#1E1E1E'},
|
style={'backgroundColor': '#1E1E1E'},
|
||||||
className='stockselector'
|
className='stockselector'
|
||||||
)
|
)
|
||||||
@ -93,31 +96,40 @@ app.layout = html.Div(
|
|||||||
children=[
|
children=[
|
||||||
dcc.Graph(id='timeseries', config={'displayModeBar': False}, animate=True),
|
dcc.Graph(id='timeseries', config={'displayModeBar': False}, animate=True),
|
||||||
dash_table.DataTable(
|
dash_table.DataTable(
|
||||||
id='table',
|
id='stock_price_table',
|
||||||
columns=[{"name": i, "id": i} for i in tickerDf.columns],
|
style_header={'backgroundColor': 'rgb(30, 30, 30)'},
|
||||||
data=tickerDf.to_dict('records'),
|
style_cell={
|
||||||
|
'backgroundColor': 'rgb(50, 50, 50)',
|
||||||
|
'color': 'white'
|
||||||
|
},
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
])
|
])
|
||||||
]
|
]
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Callback for timeseries price
|
# Callback for timeseries price
|
||||||
@app.callback(Output('timeseries', 'figure'), [Input('stockselector', 'value')])
|
@app.callback(Output('timeseries', 'figure'), [Input('stockselector', 'value')])
|
||||||
def update_graph(selected_dropdown_value):
|
def update_graph(selected_dropdown_value):
|
||||||
subDf = tickerDf[selected_dropdown_value]
|
global selected_stocks_in_graph
|
||||||
figure = px.line(subDf, template='plotly_dark', title='Stock Prices')
|
global selected_stocks_in_graph_df
|
||||||
|
selected_stocks_in_graph = selected_dropdown_value
|
||||||
|
selected_stocks_in_graph_df = closePrices[selected_stocks_in_graph]
|
||||||
|
figure = px.line(selected_stocks_in_graph_df, template='plotly_dark', title='Stock Prices')
|
||||||
return figure
|
return figure
|
||||||
|
|
||||||
|
|
||||||
# @app.callback(Output('timeseries', 'figure'),
|
@app.callback([Output("stock_price_table", "data"), Output('stock_price_table', 'columns')],
|
||||||
# [Input('table_selector', 'value')])
|
[Input('table_selector', 'value')])
|
||||||
# def update_table(selected_dropdown_value):
|
def update_table(selected_dropdown_value):
|
||||||
# subDf = tickerDf[selected_dropdown_value]
|
global selected_stock_in_table
|
||||||
# figure = px.line(subDf, template='plotly_dark', title='Stock Prices')
|
global selected_stock_in_table_df
|
||||||
# return figure
|
selected_stock_in_table = selected_dropdown_value
|
||||||
|
selected_stock_in_table_df = fullTableDf.xs(selected_stock_in_table, axis=1, level=1)
|
||||||
|
data = selected_stock_in_table_df.to_dict('records')
|
||||||
|
columns = [{"name": i, "id": i} for i in selected_stock_in_table_df.columns]
|
||||||
|
return data, columns
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
Reference in New Issue
Block a user