andrewammann commited on
Commit
f8a495e
·
verified ·
1 Parent(s): e766e43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -29
app.py CHANGED
@@ -2,49 +2,35 @@ from dash import Dash, html, dcc, Input, Output
2
  import pandas as pd
3
  import plotly.express as px
4
 
5
- # Load the dataset
6
- df = pd.read_csv('C:/Users/aammann/OneDrive - Great American Insurance Group/Documents/cincinnati_traffic_crash_data__cpd.csv')
7
-
8
- # Preprocess the data
9
- df_grouped = df.groupby('SNA_NEIGHBORHOOD')['DATECRASHREPORTED'].count().reset_index()
10
- df_grouped.columns = ['Neighborhood', 'Total Crashes']
11
 
12
  # Initialize the Dash app
13
  app = Dash(__name__)
14
 
15
- # Create a bar chart
16
- fig = px.bar(df_grouped, x='Neighborhood', y='Total Crashes', title='Total Traffic Crashes by Neighborhood in Cincinnati')
17
-
18
  # Define the layout of the app
19
- app.layout = html.Div(children=[
20
- html.H1(children='Cincinnati Traffic Crashes Dashboard'),
21
-
22
- html.Div(children='''Dash: A web application framework for your data.'''),
23
-
24
  dcc.Dropdown(
25
- id='neighborhood-dropdown',
26
- options=[{'label': n, 'value': n} for n in df_grouped['Neighborhood']],
27
- value=df_grouped['Neighborhood'][0]
28
  ),
29
-
30
- dcc.Graph(
31
- id='example-graph',
32
- figure=fig
33
- )
34
  ])
35
 
36
- # Callback to update graph based on dropdown selection
37
  @app.callback(
38
- Output('example-graph', 'figure'),
39
- [Input('neighborhood-dropdown', 'value')]
40
  )
41
- def update_graph(selected_neighborhood):
42
- filtered_df = df_grouped[df_grouped['Neighborhood'] == selected_neighborhood]
43
- fig = px.bar(filtered_df, x='Neighborhood', y='Total Crashes', title=f'Total Traffic Crashes in {selected_neighborhood}')
44
  return fig
45
 
46
  # Run the app
47
  if __name__ == '__main__':
48
- app.run(debug=True, port=8051)
 
49
 
50
 
 
2
  import pandas as pd
3
  import plotly.express as px
4
 
5
+ # Load the CSV file
6
+ df = pd.read_csv('cincinnati_traffic_crash_data__cpd.csv')
 
 
 
 
7
 
8
  # Initialize the Dash app
9
  app = Dash(__name__)
10
 
 
 
 
11
  # Define the layout of the app
12
+ app.layout = html.Div([
 
 
 
 
13
  dcc.Dropdown(
14
+ id='city-dropdown',
15
+ options=[{'label': city, 'value': city} for city in df['City'].unique()],
16
+ value='SF'
17
  ),
18
+ dcc.Graph(id='bar-chart')
 
 
 
 
19
  ])
20
 
21
+ # Define the callback to update the graph
22
  @app.callback(
23
+ Output('bar-chart', 'figure'),
24
+ [Input('city-dropdown', 'value')]
25
  )
26
+ def update_chart(selected_city):
27
+ filtered_df = df[df['City'] == selected_city]
28
+ fig = px.bar(filtered_df, x='Fruit', y='Amount', color='Fruit', barmode='group')
29
  return fig
30
 
31
  # Run the app
32
  if __name__ == '__main__':
33
+ app.run_server(debug=True, host='0.0.0.0', port=7860)
34
+
35
 
36