|
| 1 | +from dash import Dash, html, dcc # pip install dash |
| 2 | +import dash_mantine_components as dmc # pip install dash-mantine-components |
| 3 | +import pandas as pd # pip install pandas |
| 4 | +import plotly.express as px |
| 5 | + |
| 6 | +style = { |
| 7 | + "border": f"1px solid {dmc.theme.DEFAULT_COLORS['indigo'][4]}", |
| 8 | + "textAlign": "center", |
| 9 | +} |
| 10 | + |
| 11 | +df = pd.read_excel("https://github.com/plotly/datasets/blob/master/supermarket_sales.xlsx?raw=true", sheet_name='January') |
| 12 | + |
| 13 | +# To see all months in one data set: |
| 14 | +# list_of_dfs = [pd.read_excel("https://github.com/plotly/datasets/blob/master/supermarket_sales.xlsx?raw=true", sheet_name=x) for x in ['January', 'February', 'March']] |
| 15 | +# df = pd.concat([x for x in list_of_dfs]) |
| 16 | +# df['Month'] = df['Date'].dt.month |
| 17 | + |
| 18 | +fig1 = px.histogram(df, x='City', y='Total', color='Payment', histfunc='avg', barmode='group')#, facet_col='Month') |
| 19 | +fig2 = px.box(df, x='City', y='Unit price', color='City')#, facet_col='Month') |
| 20 | +fig3 = px.density_heatmap(df, x='Unit price', y='Rating')#, facet_col='Month') |
| 21 | +fig4 = px.strip(df, x="gross income", y="Product line")#, color='Month') |
| 22 | + |
| 23 | +app = Dash(__name__) |
| 24 | +server = app.server |
| 25 | + |
| 26 | +app.layout=dmc.Container([ |
| 27 | + html.H1("Python App from Excel"), |
| 28 | + dmc.Grid([ |
| 29 | + dmc.Col(dcc.Graph(figure=fig1, style=style), span=6), |
| 30 | + dmc.Col(dcc.Graph(figure=fig2, style=style), span=6), |
| 31 | + dmc.Col(dcc.Graph(figure=fig3, style=style), span=6), |
| 32 | + dmc.Col(dcc.Graph(figure=fig4, style=style), span=6), |
| 33 | + ], gutter="sm") |
| 34 | + |
| 35 | +], fluid=True) |
| 36 | + |
| 37 | + |
| 38 | +if __name__=='__main__': |
| 39 | + app.run_server(debug=True) |
0 commit comments