Skip to content

Instantly share code, notes, and snippets.

@fnneves
Created May 31, 2022 01:35
Show Gist options
  • Save fnneves/05fe0352cbc5a552103fedcb61991ff6 to your computer and use it in GitHub Desktop.
Save fnneves/05fe0352cbc5a552103fedcb61991ff6 to your computer and use it in GitHub Desktop.
app = JupyterDash(__name__, external_stylesheets=[dbc.themes.LUX])
# app = JupyterDash(__name__, external_stylesheets=[dbc.themes.CYBORG]) ## switch to a dark theme!
app.layout = html.Div(id='page-content', children=firstpage, className='p-3')
@app.callback(
[
Output("revenuechart", "figure"), Output("netprofitmargchart", "figure"), Output("shareschart", "figure"),
Output("ebitdachart", "figure"), Output("debtchart", "figure"), Output("freecashchart", "figure"),
Output("pricechart", "figure"), Output("sec", "children"), Output("ind", "children"),
Output("p/e", "children"), Output("comp", "children"), Output("pri", "children"),
],
Input('stock-dropdown', 'value')
)
def update_figure(st):
THEME='ggplot2'
MARGIN=dict(t=10, b=20, l=10, r=10)
fig_rev = px.bar(dict_income[st]['Revenue'], y='Revenue', text_auto='.3s', hover_data = {'Revenue': ':,.2d'})
fig_rev.update_layout(template=THEME, margin = MARGIN)
fig_rev.update_traces(textposition="outside", cliponaxis=False, marker_color='mediumaquamarine')
fig_net_inc = px.bar(dict_income[st]['Net Income'], y='Net Income', text_auto='.3s', hover_data = {'Net Income': ':,.2d'})
fig_net_inc.update_layout(template=THEME, margin = MARGIN)
fig_net_inc.update_traces(marker_color='skyblue', textposition="outside", cliponaxis=True)
fig_debt = px.bar(dict_balsheet[st]['Total Liabilities'], y='Total Liabilities', text_auto='.3s', hover_data = {'Total Liabilities': ':,.2d'})
fig_debt.update_layout(template=THEME, margin = MARGIN)
fig_debt.update_traces(marker_color='peachpuff', textposition="outside", cliponaxis=False)
fig_fcf = px.bar(dict_balsheet[st]['Cash On Hand'], y='Cash On Hand', text_auto='.3s', hover_data = {'Cash On Hand': ':,.2d'})
fig_fcf.update_layout(template=THEME, margin = MARGIN)
fig_fcf.update_traces(marker_color='darkturquoise', textposition="outside", cliponaxis=False)
fig_shares = px.bar(dict_income[st]['Shares Outstanding'], y='Shares Outstanding', text_auto='.3s', hover_data = {'Shares Outstanding': ':,.2d'})
fig_shares.update_layout(template=THEME, margin = MARGIN)
fig_shares.update_traces(marker_color='lightsalmon', textposition="outside", cliponaxis=False)
fig_netprof = px.bar(dict_financials[st]['Net Profit Margin'], y='Net Profit Margin', text_auto='.2f')
fig_netprof.update_layout(template=THEME, margin = MARGIN)
fig_netprof.update_traces(marker_color='darkkhaki', textposition="outside", cliponaxis=False)
fig_pricehist = px.line(dict_price[st], y='Close')
fig_pricehist.update_layout(template=THEME, margin = MARGIN)
fig_pricehist.update_traces(line_color='royalblue', line_width=3, hovertemplate='Close @ %{x}: $%{y}')
sec = 'Sector: ' + dict_overview[st]['sector'].iloc[0]
ind = 'Industry: ' + dict_overview[st]['industry'].iloc[0]
pe = 'P/E Ratio: ' + str(dict_overview[st]['p/e'].iloc[0])
comp = 'Company Name: ' + dict_overview[st]['company'].iloc[0]
pri = 'Latest Price: ' + str(dict_overview[st]['price'].iloc[0])
return fig_rev, fig_netprof, fig_shares, fig_net_inc, fig_debt, fig_fcf, fig_pricehist, sec, ind, pe, comp, pri
if __name__ == "__main__":
app.run_server(debug=True, port=8051)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment