-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdash9.py
More file actions
70 lines (62 loc) · 2.03 KB
/
dash9.py
File metadata and controls
70 lines (62 loc) · 2.03 KB
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
64
65
66
67
68
69
70
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')
product_labels = dff["Product"].unique()
# Update the y-axis titles
for i, indicator in enumerate(dff["Indicator"].unique()):
fig.update_yaxes(title_text=indicator, row=i + 1, col=1)
annotations = [
dict(
x=product,
y=1.0,
xref="x",
yref="paper",
text=product,
showarrow=False,
font=dict(size=14),
textangle=0
)
for product in product_labels
]
fig.update_layout(height=800, annotations=annotations)
return fig
if __name__ == '__main__':
app.run_server(debug=True, host="0.0.0.0", port=8080)