Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -231,40 +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 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
|
| 269 |
with tab2:
|
| 270 |
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())
|