Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -78,11 +78,12 @@ st.sidebar.header("Dashboard Controls")
|
|
| 78 |
# Defining the visualization type (viz_type) selection
|
| 79 |
viz_type = st.sidebar.selectbox("Select Visualization", [
|
| 80 |
"Complaint Types", "Geographic Distribution", "Complaints by Disposition", "Submission Methods",
|
| 81 |
-
"Monthly Trends by Complaint Type", "Complaints Over Time", "Complaints by Housing Block and Type",
|
|
|
|
| 82 |
])
|
| 83 |
|
| 84 |
# Removing the year selection when certain visualizations are selected
|
| 85 |
-
if viz_type not in ["Complaints Over Time", "Complaints by Housing Block and Type"]:
|
| 86 |
year_options = ['All Time'] + sorted(data['Year Reported'].unique().tolist())
|
| 87 |
selected_year = st.sidebar.selectbox("Select Year", options=year_options, key="year_select")
|
| 88 |
else:
|
|
@@ -93,13 +94,13 @@ if viz_type == "Complaints Over Time":
|
|
| 93 |
start_date = st.sidebar.date_input("Start Date", pd.to_datetime("2020-01-01"), key="start_date")
|
| 94 |
end_date = st.sidebar.date_input("End Date", pd.to_datetime("2024-12-31"), key="end_date")
|
| 95 |
|
| 96 |
-
# Dropdown for Housing Block (only show when Complaints by Housing Block and Type is selected)
|
| 97 |
-
if viz_type
|
| 98 |
block_options = ['All Blocks'] + sorted(data['Housing Block'].unique().tolist())
|
| 99 |
selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options, key="block_select")
|
| 100 |
|
| 101 |
# Ensuring selected_block is only used if defined
|
| 102 |
-
if viz_type
|
| 103 |
selected_block = 'All Blocks' # Default to 'All Blocks' if no selection made
|
| 104 |
|
| 105 |
# Filtering data based on selected year
|
|
@@ -121,15 +122,14 @@ if viz_type == "Complaints Over Time":
|
|
| 121 |
else:
|
| 122 |
filtered_data_time = filtered_data
|
| 123 |
|
| 124 |
-
# Filtering data based on selected housing block (only for Complaints by Housing Block
|
| 125 |
-
if viz_type
|
| 126 |
filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
|
| 127 |
|
| 128 |
# Header for selected year
|
| 129 |
st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selected_year}")
|
| 130 |
|
| 131 |
|
| 132 |
-
|
| 133 |
# Displaying metrics
|
| 134 |
col1, col2 = st.columns(2)
|
| 135 |
with col1:
|
|
|
|
| 78 |
# Defining the visualization type (viz_type) selection
|
| 79 |
viz_type = st.sidebar.selectbox("Select Visualization", [
|
| 80 |
"Complaint Types", "Geographic Distribution", "Complaints by Disposition", "Submission Methods",
|
| 81 |
+
"Monthly Trends by Complaint Type", "Complaints Over Time", "Complaints by Housing Block and Type",
|
| 82 |
+
"Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)"
|
| 83 |
])
|
| 84 |
|
| 85 |
# Removing the year selection when certain visualizations are selected
|
| 86 |
+
if viz_type not in ["Complaints Over Time", "Complaints by Housing Block and Type", "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)"]:
|
| 87 |
year_options = ['All Time'] + sorted(data['Year Reported'].unique().tolist())
|
| 88 |
selected_year = st.sidebar.selectbox("Select Year", options=year_options, key="year_select")
|
| 89 |
else:
|
|
|
|
| 94 |
start_date = st.sidebar.date_input("Start Date", pd.to_datetime("2020-01-01"), key="start_date")
|
| 95 |
end_date = st.sidebar.date_input("End Date", pd.to_datetime("2024-12-31"), key="end_date")
|
| 96 |
|
| 97 |
+
# Dropdown for Housing Block (only show when Complaints by Housing Block and Type or the updated version is selected)
|
| 98 |
+
if viz_type in ["Complaints by Housing Block and Type", "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)"]:
|
| 99 |
block_options = ['All Blocks'] + sorted(data['Housing Block'].unique().tolist())
|
| 100 |
selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options, key="block_select")
|
| 101 |
|
| 102 |
# Ensuring selected_block is only used if defined
|
| 103 |
+
if viz_type in ["Complaints by Housing Block and Type", "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)"] and 'selected_block' not in locals():
|
| 104 |
selected_block = 'All Blocks' # Default to 'All Blocks' if no selection made
|
| 105 |
|
| 106 |
# Filtering data based on selected year
|
|
|
|
| 122 |
else:
|
| 123 |
filtered_data_time = filtered_data
|
| 124 |
|
| 125 |
+
# Filtering data based on selected housing block (only for Complaints by Housing Block and the updated version)
|
| 126 |
+
if viz_type in ["Complaints by Housing Block and Type", "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)"] and selected_block != 'All Blocks':
|
| 127 |
filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
|
| 128 |
|
| 129 |
# Header for selected year
|
| 130 |
st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selected_year}")
|
| 131 |
|
| 132 |
|
|
|
|
| 133 |
# Displaying metrics
|
| 134 |
col1, col2 = st.columns(2)
|
| 135 |
with col1:
|