Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -121,7 +121,8 @@ def get_top_violations(df, age_group):
|
|
| 121 |
return violations_df.head()
|
| 122 |
|
| 123 |
# added interactivity pie plot for part3 (linked with crash stats visualization)
|
| 124 |
-
def create_interactive_pie_chart(violations, selected_violation):
|
|
|
|
| 125 |
# Filter data based on selected violation
|
| 126 |
filtered_data = violations[violations['Violation'] == selected_violation]
|
| 127 |
|
|
@@ -130,7 +131,8 @@ def create_interactive_pie_chart(violations, selected_violation):
|
|
| 130 |
filtered_data,
|
| 131 |
names='Severity',
|
| 132 |
values='count',
|
| 133 |
-
title=f'Severity Level Distribution for Violation: {selected_violation}',
|
|
|
|
| 134 |
height=600,
|
| 135 |
color_discrete_map=severity_colors
|
| 136 |
)
|
|
@@ -418,7 +420,8 @@ def main():
|
|
| 418 |
|
| 419 |
# If a violation is selected, display the pie chart --> added for part3 (interactive pie chart)
|
| 420 |
if st.session_state['selected_violation']:
|
| 421 |
-
pie_chart = create_interactive_pie_chart(violations, st.session_state['selected_violation'])
|
|
|
|
| 422 |
st.plotly_chart(pie_chart, use_container_width=True)
|
| 423 |
|
| 424 |
# Display statistics
|
|
|
|
| 121 |
return violations_df.head()
|
| 122 |
|
| 123 |
# added interactivity pie plot for part3 (linked with crash stats visualization)
|
| 124 |
+
# def create_interactive_pie_chart(violations, selected_violation):
|
| 125 |
+
def create_interactive_pie_chart(violations, selected_violation, selected_age):
|
| 126 |
# Filter data based on selected violation
|
| 127 |
filtered_data = violations[violations['Violation'] == selected_violation]
|
| 128 |
|
|
|
|
| 131 |
filtered_data,
|
| 132 |
names='Severity',
|
| 133 |
values='count',
|
| 134 |
+
# title=f'Severity Level Distribution for Violation: {selected_violation}',
|
| 135 |
+
title=f'Severity Level Distribution for Violation: {selected_violation} - {selected_age}', # dynamically update pie chart's title
|
| 136 |
height=600,
|
| 137 |
color_discrete_map=severity_colors
|
| 138 |
)
|
|
|
|
| 420 |
|
| 421 |
# If a violation is selected, display the pie chart --> added for part3 (interactive pie chart)
|
| 422 |
if st.session_state['selected_violation']:
|
| 423 |
+
# pie_chart = create_interactive_pie_chart(violations, st.session_state['selected_violation'])
|
| 424 |
+
pie_chart = create_interactive_pie_chart(violations, st.session_state['selected_violation'], selected_age) # dynamically update pie chart's title
|
| 425 |
st.plotly_chart(pie_chart, use_container_width=True)
|
| 426 |
|
| 427 |
# Display statistics
|