Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,7 +10,7 @@ from datetime import datetime, timedelta
|
|
| 10 |
# CONFIG & TITLE
|
| 11 |
# -----------------------------
|
| 12 |
st.set_page_config(page_title="San José Crash Dashboard", layout="wide")
|
| 13 |
-
st.title("
|
| 14 |
st.markdown("Explore live crash data from the San José Open Data Portal using interactive charts and maps.")
|
| 15 |
|
| 16 |
# -----------------------------
|
|
@@ -60,15 +60,15 @@ def filter_by_date(df, months):
|
|
| 60 |
return df[(df["CrashDateTime"] >= start_date) & (df["CrashDateTime"] <= end_date)]
|
| 61 |
|
| 62 |
# -----------------------------
|
| 63 |
-
#
|
| 64 |
# -----------------------------
|
| 65 |
st.sidebar.title("Navigation")
|
| 66 |
page = st.sidebar.radio("Go to", [
|
| 67 |
-
"
|
| 68 |
-
"
|
| 69 |
-
"
|
| 70 |
-
"
|
| 71 |
-
"
|
| 72 |
])
|
| 73 |
|
| 74 |
months = st.sidebar.selectbox("Select Time Range", ["3", "6", "9", "12", "All"], index=3, format_func=lambda x: f"{x} Months" if x != "All" else "All Time")
|
|
@@ -79,7 +79,7 @@ df = preprocess(fetch_data())
|
|
| 79 |
df = filter_by_date(df, months)
|
| 80 |
|
| 81 |
# Render pages dynamically
|
| 82 |
-
if page == "
|
| 83 |
st.header("Weather Conditions vs Injury Severity")
|
| 84 |
st.markdown("See how different weather patterns affect the severity of crash injuries in San José.")
|
| 85 |
|
|
@@ -118,7 +118,7 @@ elif page == "🚗 Speeding Trends":
|
|
| 118 |
).properties(height=450)
|
| 119 |
st.altair_chart(chart, use_container_width=True)
|
| 120 |
|
| 121 |
-
elif page == "
|
| 122 |
st.header("Crash Locations in San José")
|
| 123 |
st.markdown("Zoom in to spot areas with high crash density.")
|
| 124 |
|
|
@@ -142,7 +142,7 @@ elif page == "🗺️ Crash Map":
|
|
| 142 |
],
|
| 143 |
))
|
| 144 |
|
| 145 |
-
elif page == "
|
| 146 |
st.header("Crash Count by Road Surface Condition")
|
| 147 |
st.markdown("Are certain road surface types more accident-prone?")
|
| 148 |
|
|
@@ -154,7 +154,7 @@ elif page == "🛣️ Road Surface Analysis":
|
|
| 154 |
).properties(height=450)
|
| 155 |
st.altair_chart(chart, use_container_width=True)
|
| 156 |
|
| 157 |
-
elif page == "
|
| 158 |
st.header("Correlation Among Injury Stats")
|
| 159 |
st.markdown("Explore numeric relationships between injury types and year.")
|
| 160 |
|
|
|
|
| 10 |
# CONFIG & TITLE
|
| 11 |
# -----------------------------
|
| 12 |
st.set_page_config(page_title="San José Crash Dashboard", layout="wide")
|
| 13 |
+
st.title("San José Real-Time Crash Dashboard")
|
| 14 |
st.markdown("Explore live crash data from the San José Open Data Portal using interactive charts and maps.")
|
| 15 |
|
| 16 |
# -----------------------------
|
|
|
|
| 60 |
return df[(df["CrashDateTime"] >= start_date) & (df["CrashDateTime"] <= end_date)]
|
| 61 |
|
| 62 |
# -----------------------------
|
| 63 |
+
# Navigation sidebar
|
| 64 |
# -----------------------------
|
| 65 |
st.sidebar.title("Navigation")
|
| 66 |
page = st.sidebar.radio("Go to", [
|
| 67 |
+
"Weather & Injuries",
|
| 68 |
+
"Speeding Trends",
|
| 69 |
+
"Crash Map",
|
| 70 |
+
"Road Surface Analysis",
|
| 71 |
+
"Injury Correlation"
|
| 72 |
])
|
| 73 |
|
| 74 |
months = st.sidebar.selectbox("Select Time Range", ["3", "6", "9", "12", "All"], index=3, format_func=lambda x: f"{x} Months" if x != "All" else "All Time")
|
|
|
|
| 79 |
df = filter_by_date(df, months)
|
| 80 |
|
| 81 |
# Render pages dynamically
|
| 82 |
+
if page == "Weather & Injuries":
|
| 83 |
st.header("Weather Conditions vs Injury Severity")
|
| 84 |
st.markdown("See how different weather patterns affect the severity of crash injuries in San José.")
|
| 85 |
|
|
|
|
| 118 |
).properties(height=450)
|
| 119 |
st.altair_chart(chart, use_container_width=True)
|
| 120 |
|
| 121 |
+
elif page == "Crash Map":
|
| 122 |
st.header("Crash Locations in San José")
|
| 123 |
st.markdown("Zoom in to spot areas with high crash density.")
|
| 124 |
|
|
|
|
| 142 |
],
|
| 143 |
))
|
| 144 |
|
| 145 |
+
elif page == "Road Surface Analysis":
|
| 146 |
st.header("Crash Count by Road Surface Condition")
|
| 147 |
st.markdown("Are certain road surface types more accident-prone?")
|
| 148 |
|
|
|
|
| 154 |
).properties(height=450)
|
| 155 |
st.altair_chart(chart, use_container_width=True)
|
| 156 |
|
| 157 |
+
elif page == "Injury Correlation":
|
| 158 |
st.header("Correlation Among Injury Stats")
|
| 159 |
st.markdown("Explore numeric relationships between injury types and year.")
|
| 160 |
|