-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgui.py
55 lines (50 loc) · 1.43 KB
/
gui.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
import dash
from dash import dcc
from dash import html
from dash.dependencies import Input, Output
import plotly.express as px
# Sample data
import pandas as pd
df = pd.DataFrame({
'Category': ['A', 'B', 'C'],
'Value': [1, 2, 3]
})
# Initialize the Dash app
app = dash.Dash(__name__)
# Define the layout of the app
app.layout = html.Div(
children=[
html.H1("Interactive Visualization Tool"),
html.Div(
children=[
dcc.Dropdown(
id='category-dropdown',
options=[
{'label': category, 'value': category}
for category in df['Category']
],
value=df['Category'][0],
multi=False,
style={'width': '50%'}
),
],
style={'margin-bottom': '20px'}
),
dcc.Graph(
id='bar-chart'
),
],
style={'textAlign': 'center', 'margin': '50px'}
)
# Define callbacks to update the graph based on user input
@app.callback(
Output('bar-chart', 'figure'),
[Input('category-dropdown', 'value')]
)
def update_graph(selected_category):
filtered_df = df[df['Category'] == selected_category]
fig = px.bar(filtered_df, x='Category', y='Value', title=f'Bar Chart for {selected_category}')
return fig
# Run the app
if __name__ == '__main__':
app.run_server(debug=True)