Update src/streamlit_app.py
Browse files- src/streamlit_app.py +11 -4
src/streamlit_app.py
CHANGED
|
@@ -31,7 +31,7 @@ st.markdown("""
|
|
| 31 |
font-family: 'Source Sans Pro', sans-serif;
|
| 32 |
font-size: 32px;
|
| 33 |
color: #2c3e50;
|
| 34 |
-
margin-top:
|
| 35 |
margin-bottom: 10px;
|
| 36 |
border-bottom: 3px solid #ccc;
|
| 37 |
padding-bottom: 8px;
|
|
@@ -51,11 +51,11 @@ design targeted strategies to improve public safety.</div>""",unsafe_allow_html=
|
|
| 51 |
# 2. Data info & load
|
| 52 |
st.markdown("<div class='sectionheader'> Dataset Information </div>", unsafe_allow_html=True)
|
| 53 |
st.markdown(
|
| 54 |
-
"""
|
| 55 |
- **Source:** LAPD crime incidents dataset
|
| 56 |
- **Rows:** incidents (one per row)
|
| 57 |
- **Columns:** e.g. `crm_cd_desc` (crime type), `arrest` (boolean), `date`, `location_description`, etc.
|
| 58 |
-
- **Purpose:** Interactive exploration of top crime categories and arrest rates.
|
| 59 |
"""
|
| 60 |
)
|
| 61 |
|
|
@@ -66,7 +66,7 @@ DATA_PATH = Path(__file__).parent / "crime_data.csv" # /app/src/crime_dat
|
|
| 66 |
def load_data():
|
| 67 |
return pd.read_csv(DATA_PATH)
|
| 68 |
|
| 69 |
-
if st.button("🔄"):
|
| 70 |
st.cache_data.clear() # Clear the cache
|
| 71 |
st.toast("Data is refreshed",icon="✅") # Reload the data
|
| 72 |
|
|
@@ -78,6 +78,13 @@ if df.empty:
|
|
| 78 |
# 3. Data preview
|
| 79 |
st.markdown("<div class='sectionheader'> Data Preview </div>", unsafe_allow_html=True)
|
| 80 |
st.write(f"Total records: {df.shape[0]} | Total columns: {df.shape[1]}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
st.dataframe(df.head())
|
| 82 |
|
| 83 |
# Pie Chart 1: Top 10 Crime Types
|
|
|
|
| 31 |
font-family: 'Source Sans Pro', sans-serif;
|
| 32 |
font-size: 32px;
|
| 33 |
color: #2c3e50;
|
| 34 |
+
margin-top: 15px;
|
| 35 |
margin-bottom: 10px;
|
| 36 |
border-bottom: 3px solid #ccc;
|
| 37 |
padding-bottom: 8px;
|
|
|
|
| 51 |
# 2. Data info & load
|
| 52 |
st.markdown("<div class='sectionheader'> Dataset Information </div>", unsafe_allow_html=True)
|
| 53 |
st.markdown(
|
| 54 |
+
""" <div class='description'>
|
| 55 |
- **Source:** LAPD crime incidents dataset
|
| 56 |
- **Rows:** incidents (one per row)
|
| 57 |
- **Columns:** e.g. `crm_cd_desc` (crime type), `arrest` (boolean), `date`, `location_description`, etc.
|
| 58 |
+
- **Purpose:** Interactive exploration of top crime categories and arrest rates.</div>
|
| 59 |
"""
|
| 60 |
)
|
| 61 |
|
|
|
|
| 66 |
def load_data():
|
| 67 |
return pd.read_csv(DATA_PATH)
|
| 68 |
|
| 69 |
+
if st.button("🔄 Refresh Data"):
|
| 70 |
st.cache_data.clear() # Clear the cache
|
| 71 |
st.toast("Data is refreshed",icon="✅") # Reload the data
|
| 72 |
|
|
|
|
| 78 |
# 3. Data preview
|
| 79 |
st.markdown("<div class='sectionheader'> Data Preview </div>", unsafe_allow_html=True)
|
| 80 |
st.write(f"Total records: {df.shape[0]} | Total columns: {df.shape[1]}")
|
| 81 |
+
st.markdown(
|
| 82 |
+
f"<div class='description'>"
|
| 83 |
+
f"Total records: <strong>{df.shape[0]:,}</strong> | "
|
| 84 |
+
f"Total columns: <strong>{df.shape[1]:,}</strong>"
|
| 85 |
+
f"</div>",
|
| 86 |
+
unsafe_allow_html=True
|
| 87 |
+
)
|
| 88 |
st.dataframe(df.head())
|
| 89 |
|
| 90 |
# Pie Chart 1: Top 10 Crime Types
|