Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -128,7 +128,8 @@ def get_top_violations(df, age_group):
|
|
128 |
return violations_df.head()
|
129 |
|
130 |
# added interactivity pie plot for part3 (linked with crash stats visualization)
|
131 |
-
def create_interactive_pie_chart(violations, selected_violation):
|
|
|
132 |
# Filter data based on selected violation
|
133 |
filtered_data = violations[violations['Violation'] == selected_violation]
|
134 |
|
@@ -137,7 +138,8 @@ def create_interactive_pie_chart(violations, selected_violation):
|
|
137 |
filtered_data,
|
138 |
names='Severity',
|
139 |
values='count',
|
140 |
-
title=f'Severity Level Distribution for Violation: {selected_violation}',
|
|
|
141 |
height=600,
|
142 |
color_discrete_map=severity_colors
|
143 |
)
|
@@ -425,7 +427,8 @@ def main():
|
|
425 |
|
426 |
# If a violation is selected, display the pie chart --> added for part3 (interactive pie chart)
|
427 |
if st.session_state['selected_violation']:
|
428 |
-
pie_chart = create_interactive_pie_chart(violations, st.session_state['selected_violation'])
|
|
|
429 |
st.plotly_chart(pie_chart, use_container_width=True)
|
430 |
|
431 |
# Display statistics
|
|
|
128 |
return violations_df.head()
|
129 |
|
130 |
# added interactivity pie plot for part3 (linked with crash stats visualization)
|
131 |
+
# def create_interactive_pie_chart(violations, selected_violation):
|
132 |
+
def create_interactive_pie_chart(violations, selected_violation, selected_age):
|
133 |
# Filter data based on selected violation
|
134 |
filtered_data = violations[violations['Violation'] == selected_violation]
|
135 |
|
|
|
138 |
filtered_data,
|
139 |
names='Severity',
|
140 |
values='count',
|
141 |
+
# title=f'Severity Level Distribution for Violation: {selected_violation}',
|
142 |
+
title=f'Severity Level Distribution for Violation: {selected_violation} - {selected_age}', # dynamically update pie chart's title
|
143 |
height=600,
|
144 |
color_discrete_map=severity_colors
|
145 |
)
|
|
|
427 |
|
428 |
# If a violation is selected, display the pie chart --> added for part3 (interactive pie chart)
|
429 |
if st.session_state['selected_violation']:
|
430 |
+
# pie_chart = create_interactive_pie_chart(violations, st.session_state['selected_violation'])
|
431 |
+
pie_chart = create_interactive_pie_chart(violations, st.session_state['selected_violation'], selected_age) # dynamically update pie chart's title
|
432 |
st.plotly_chart(pie_chart, use_container_width=True)
|
433 |
|
434 |
# Display statistics
|