Created
October 13, 2020 15:57
-
-
Save phillipsj/8c18ace8ca5a54f6a18fd7a5edd382d0 to your computer and use it in GitHub Desktop.
Complete Dash Tutorial file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import dash | |
import dash_core_components as dcc | |
import dash_html_components as html | |
import plotly.express as px | |
import pandas as pd | |
from sqlalchemy import create_engine | |
app = dash.Dash(__name__) | |
engine = create_engine( | |
"mssql+pyodbc://sa:ThisIsAReallyCoolPassword123@localhost:1633/AdventureWorks2019?driver=ODBC+Driver+17+for+SQL+Server") | |
query = ''' | |
SELECT CONCAT([FirstName],' ', [LastName]) as Name, | |
[SalesQuota], | |
[SalesYTD] | |
FROM [Sales].[vSalesPerson] | |
''' | |
df = pd.read_sql(query, engine) | |
salesFigure = px.bar(df, x="Name", y="SalesYTD", color="Name", barmode="group") | |
quotaFigure = px.bar(df, x="Name", y="SalesQuota", color="Name", barmode="group") | |
app.layout = html.Div(children=[ | |
html.H1(children='Adventure Works Sales Report'), | |
html.Div(children=''' | |
YTD Sales by Individual. | |
'''), | |
dcc.Graph( | |
id='sales-graph', | |
figure=salesFigure | |
), | |
html.Div(children=''' | |
Quota by Individual. | |
'''), | |
dcc.Graph( | |
id='quota-graph', | |
figure=quotaFigure | |
) | |
]) | |
if __name__ == '__main__': | |
app.run_server(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment