Skip to content

Instantly share code, notes, and snippets.

@dunithd
Created October 9, 2021 02:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dunithd/143261ce3f6428c5c2f7b89403e22314 to your computer and use it in GitHub Desktop.
Save dunithd/143261ce3f6428c5c2f7b89403e22314 to your computer and use it in GitHub Desktop.
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