-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdash7.py
More file actions
62 lines (56 loc) · 2.12 KB
/
dash7.py
File metadata and controls
62 lines (56 loc) · 2.12 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
import dash
from dash.dependencies import Input, Output
from dash import dcc
from dash import html
import pandas as pd
import plotly.express as px
# Read data from CSV file
df = pd.read_csv('data256.csv')
# Create a dash app
app = dash.Dash(__name__)
# Define the layout of the app
app.layout = html.Div([
# Add a drop-down menu for selecting the graph type
dcc.Dropdown(
id='graph-type',
options=[
{'label': 'Sunburst', 'value': 'sunburst'},
{'label': 'Vertical Bar', 'value': 'vbar'},
{'label': 'Horizontal Bar', 'value': 'hbar'}
],
value='sunburst'
),
# Add a drop-down menu for selecting the zone
dcc.Dropdown(
id='zone',
options=[{'label': zone, 'value': zone} for zone in df['Zones'].unique()],
value=df['Zones'].iloc[0]
),
# Add a container for displaying the selected graph
dcc.Graph(id='graph')
])
# Define a callback function to update the displayed graph
@app.callback(
Output('graph', 'figure'),
[Input('graph-type', 'value'), Input('zone', 'value')]
)
def update_graph(graph_type, zone):
# Filter data by selected zone
df_filtered = df[df['Zones'] == zone]
if graph_type == 'sunburst':
# Create a sunburst chart using plotly
fig = px.sunburst(df_filtered, path=['Indicator', 'Product', 'Metric'], values='Value')
elif graph_type == 'vbar':
# Create a vertical bar chart using plotly
fig = px.bar(df_filtered, x='Product', y='Value', color='Metric', barmode='group', facet_row='Indicator')
# Increase the distance between rows of subplots
fig.update_layout(height=800)
elif graph_type == 'hbar':
# Create a horizontal bar chart using plotly
fig = px.bar(df_filtered, y='Product', x='Value', color='Metric', barmode='group', facet_row='Indicator')
# Increase the distance between rows of subplots
fig.update_layout(height=800)
return fig
# Run the app on a local server
if __name__ == '__main__':
app.run_server(debug=True, host="0.0.0.0", port=8080)