-
Notifications
You must be signed in to change notification settings - Fork 0
/
dash10.py
63 lines (56 loc) · 1.69 KB
/
dash10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import dash
from dash import dcc, html
from dash.dependencies import Input, Output
import plotly.express as px
import pandas as pd
app = dash.Dash(__name__)
df = pd.read_csv('data256.csv')
app.layout = html.Div([
dcc.Dropdown(
id='graph-type',
options=[
{'label': 'Sunburst', 'value': 'sunburst'},
{'label': 'Barplot', 'value': 'barplot'}
],
value='sunburst'
),
dcc.Dropdown(
id='zone',
options=[{'label': i, 'value': i} for i in df['Zones'].unique()],
value='National'
),
dcc.Graph(id='indicator-graph')
])
@app.callback(
Output('zone', 'style'),
Input('graph-type', 'value'))
def toggle_zone_dropdown(graph_type):
if graph_type == 'sunburst':
return {'display': 'none'}
else:
return {'display': 'block'}
@app.callback(
Output('indicator-graph', 'figure'),
Input('graph-type', 'value'),
Input('zone', 'value'))
def update_graph(graph_type, zone):
if graph_type == 'sunburst':
fig = px.sunburst(df, path=['Zones', 'Product', 'Indicator', 'Metric'], values='Value')
else:
dff = df[df['Zones'] == zone]
fig = px.bar(dff, x='Product', y='Value', color='Metric', barmode='group', facet_row='Indicator')
fig.update_layout(
height=800,
xaxis=dict(
title=None,
showticklabels=False
),
xaxis4=dict(
side='top',
showticklabels=True,
title=dict(text='Product')
)
)
return fig
if __name__ == '__main__':
app.run_server(debug=True, host="0.0.0.0", port=8080)