Created
October 9, 2021 02:24
-
-
Save dunithd/143261ce3f6428c5c2f7b89403e22314 to your computer and use it in GitHub Desktop.
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 psycopg2 | |
import pandas.io.sql as sqlio | |
import pandas as pd | |
import dash | |
from dash import dcc | |
from dash import html | |
import plotly.express as px | |
app = dash.Dash(__name__) | |
# Connect to an existing database | |
conn = psycopg2.connect("dbname=materialize user=materialize port=6875 host=localhost") | |
sql = "select * from sales_by_customer;" | |
df = pd.read_sql_query(sql, conn) | |
fig = px.bar(df, x="customer_id", y="total_order_value") | |
# Main UI scaffolding | |
app.layout = html.Div(children=[ | |
html.H1(children='Sales by customer'), | |
html.Div(children=''' | |
Dash: A web application framework for your data. | |
'''), | |
dcc.Graph( | |
id='bar-chart', | |
figure=fig | |
) | |
]) | |
if __name__ == '__main__': | |
app.run_server(debug=True) | |
conn = None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment