from dash import Dash, html, dcc, Input, Output
import pandas as pd
import plotly.express as px
# Load the CSV file
df = pd.read_csv('cincinnati_traffic_crash_data__cpd.csv')
# Initialize the Dash app
app = Dash(__name__)
# Define the layout of the app
app.layout = html.Div([
dcc.Dropdown(
id='city-dropdown',
options=[{'label': city, 'value': city} for city in df['City'].unique()],
value='SF'
),
dcc.Graph(id='bar-chart')
])
# Define the callback to update the graph
@app.callback(
Output('bar-chart', 'figure'),
[Input('city-dropdown', 'value')]
)
def update_chart(selected_city):
filtered_df = df[df['City'] == selected_city]
fig = px.bar(filtered_df, x='Fruit', y='Amount', color='Fruit', barmode='group')
return fig
# Run the app
if __name__ == '__main__':
app.run_server(debug=True, host='0.0.0.0', port=7860)