Skip to content

Instantly share code, notes, and snippets.

@dunithd
Created October 9, 2021 02:24

Revisions

  1. dunithd created this gist Oct 9, 2021.
    37 changes: 37 additions & 0 deletions app.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    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