-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathavo-app.py
39 lines (31 loc) · 1.05 KB
/
avo-app.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
# Import libraries
from dash import Dash, html, dcc, Input, Output
import pandas as pd
import plotly.express as px
# Load the dataset
df = pd.read_csv('Resources/avocado-updated-2020.csv')
# Create the Dash app
app = Dash()
# Set up the app layout
geo_dropdown = dcc.Dropdown(options=df['geography'].unique(),
value='San Diego')
app.layout = html.Div(children=[
html.H1(children='Avocado Prices Dashboard'),
geo_dropdown,
dcc.Graph(id='price-graph')
])
# Set up the callback function
@app.callback(
Output(component_id='price-graph', component_property='figure'),
Input(component_id=geo_dropdown, component_property='value')
)
def update_graph(selected_geography):
filtered_df = df[df['geography'] == selected_geography]
line_fig = px.line(filtered_df,
x='date', y='average_price',
color='type',
title=f'Avocado Prices in {selected_geography}')
return line_fig
# Run local server
if __name__ == '__main__':
app.run_server(debug=True)