Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import folium
|
3 |
from folium.plugins import MarkerCluster, HeatMap
|
4 |
-
|
5 |
import plotly.express as px
|
6 |
|
7 |
# Function to create the map
|
@@ -76,16 +77,18 @@ def app():
|
|
76 |
# Bar Chart visualization
|
77 |
st.subheader("Accidents by Severity")
|
78 |
bar_chart = create_bar_chart(df, selected_year)
|
79 |
-
selected_points = st.plotly_chart(bar_chart)
|
80 |
|
81 |
-
#
|
|
|
82 |
if selected_points:
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
85 |
|
86 |
# Map visualization
|
87 |
st.subheader("Accidents Map")
|
88 |
-
selected_severity = st.session_state["selected_severity"]
|
89 |
map_obj = create_map(df, selected_year, selected_severity)
|
90 |
st.components.v1.html(map_obj._repr_html_(), height=600)
|
91 |
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
import folium
|
4 |
from folium.plugins import MarkerCluster, HeatMap
|
5 |
+
from streamlit_plotly_events import plotly_events
|
6 |
import plotly.express as px
|
7 |
|
8 |
# Function to create the map
|
|
|
77 |
# Bar Chart visualization
|
78 |
st.subheader("Accidents by Severity")
|
79 |
bar_chart = create_bar_chart(df, selected_year)
|
|
|
80 |
|
81 |
+
# Capture user interaction
|
82 |
+
selected_points = plotly_events(bar_chart, click_event=True, hover_event=False)
|
83 |
if selected_points:
|
84 |
+
# Get the selected severity from the clicked bar
|
85 |
+
selected_severity = selected_points[0]['x']
|
86 |
+
st.session_state["selected_severity"] = selected_severity
|
87 |
+
else:
|
88 |
+
selected_severity = st.session_state["selected_severity"]
|
89 |
|
90 |
# Map visualization
|
91 |
st.subheader("Accidents Map")
|
|
|
92 |
map_obj = create_map(df, selected_year, selected_severity)
|
93 |
st.components.v1.html(map_obj._repr_html_(), height=600)
|
94 |
|