msa17 commited on
Commit
604aa57
·
verified ·
1 Parent(s): 16a6015

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -28
app.py CHANGED
@@ -231,34 +231,40 @@ def main():
231
  tab1, tab2, tab3, tab4, tab5 = st.tabs(["Crash Statistics", "Crash Map", "Crash Trend", "Crash Injuries/Fatalities","Distribution by Category"])
232
 
233
  with tab1:
234
- # Age group selection
235
- age_groups = ['All Ages', '16-25', '26-35', '36-45', '46-55', '56-65', '65+']
236
- selected_age = st.selectbox('Select Age Group:', age_groups)
237
-
238
- # Create and display the main violation distribution chart
239
- fig, violations = create_violation_distribution_chart(df, selected_age)
240
-
241
- # Use plotly_events to capture click
242
- selected_points = plotly_events(fig, click_event=True, hover_event=False, select_event=True)
243
-
244
-
245
- # If user clicked on a bar, show severity distribution
246
- if selected_points:
247
- clicked_violation = violations.iloc[selected_points[0]['pointIndex']]['Violation']
248
- severity_fig = create_severity_distribution_for_violation(df, clicked_violation)
249
- st.plotly_chart(severity_fig, use_container_width=True)
250
-
251
- # Display total incidents info
252
- if selected_age == 'All Ages':
253
- total_incidents = len(df)
254
- else:
255
- total_incidents = len(df[
256
- (df['Age_Group_Drv1'] == selected_age) |
257
- (df['Age_Group_Drv2'] == selected_age)
258
- ])
259
-
260
- st.markdown(f"### Total Incidents for {selected_age}")
261
- st.markdown(f"**{total_incidents:,}** incidents")
 
 
 
 
 
 
262
 
263
  with tab2:
264
  years = sorted(df['Year'].unique())
 
231
  tab1, tab2, tab3, tab4, tab5 = st.tabs(["Crash Statistics", "Crash Map", "Crash Trend", "Crash Injuries/Fatalities","Distribution by Category"])
232
 
233
  with tab1:
234
+ # Age group selection
235
+ age_groups = ['All Ages', '16-25', '26-35', '36-45', '46-55', '56-65', '65+']
236
+ selected_age = st.selectbox('Select Age Group:', age_groups)
237
+
238
+ # Create and display the main violation distribution chart
239
+ fig, violations = create_violation_distribution_chart(df, selected_age)
240
+
241
+ # Display the figure using plotly_events only (no extra st.plotly_chart)
242
+ selected_points = plotly_events(
243
+ fig,
244
+ click_event=True,
245
+ hover_event=False,
246
+ select_event=True,
247
+ key="violation_chart"
248
+ )
249
+
250
+ # If user clicked on a bar, show severity distribution
251
+ if selected_points:
252
+ clicked_violation = violations.iloc[selected_points[0]['pointIndex']]['Violation']
253
+ severity_fig = create_severity_distribution_for_violation(df, clicked_violation)
254
+ st.plotly_chart(severity_fig, use_container_width=True)
255
+
256
+ # Display total incidents info
257
+ if selected_age == 'All Ages':
258
+ total_incidents = len(df)
259
+ else:
260
+ total_incidents = len(df[
261
+ (df['Age_Group_Drv1'] == selected_age) |
262
+ (df['Age_Group_Drv2'] == selected_age)
263
+ ])
264
+
265
+ st.markdown(f"### Total Incidents for {selected_age}")
266
+ st.markdown(f"**{total_incidents:,}** incidents")
267
+
268
 
269
  with tab2:
270
  years = sorted(df['Year'].unique())