ralate2 commited on
Commit
88098e3
·
verified ·
1 Parent(s): 29c6866

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -94,6 +94,10 @@ if viz_type == "Complaints by Housing Block and Type":
94
  block_options = ['All Blocks'] + sorted(data['Housing Block'].unique().tolist())
95
  selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options)
96
 
 
 
 
 
97
  # Filter data based on selected year
98
  if selected_year != 'All Time':
99
  filtered_data = data[data['Year Reported'] == selected_year]
@@ -101,7 +105,7 @@ else:
101
  filtered_data = data
102
 
103
  # Further filter by Housing Block
104
- if selected_block != 'All Blocks':
105
  filtered_data = filtered_data[filtered_data['Housing Block'] == selected_block]
106
 
107
  # Filter data based on date range (only for Complaints Over Time visualization)
@@ -122,6 +126,7 @@ st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selecte
122
 
123
 
124
 
 
125
  # Display metrics
126
  col1, col2 = st.columns(2)
127
  with col1:
@@ -327,7 +332,7 @@ elif viz_type == "Complaints by Housing Block and Type":
327
  # Plot the data
328
  fig = complaint_pivot.plot(kind='bar', stacked=True, colormap='inferno', figsize=(10, 6)).get_figure()
329
  st.pyplot(fig)
330
-
331
  st.write("""
332
  **What this visualization shows:**
333
  This line chart shows the trend of complaints over time, displaying the number of complaints reported for each day. It helps identify patterns, peaks, and trends in the complaints data.
 
94
  block_options = ['All Blocks'] + sorted(data['Housing Block'].unique().tolist())
95
  selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options)
96
 
97
+ # Ensure selected_block is only used if defined
98
+ if viz_type == "Complaints by Housing Block and Type" and 'selected_block' not in locals():
99
+ selected_block = 'All Blocks' # Default to 'All Blocks' if no selection made
100
+
101
  # Filter data based on selected year
102
  if selected_year != 'All Time':
103
  filtered_data = data[data['Year Reported'] == selected_year]
 
105
  filtered_data = data
106
 
107
  # Further filter by Housing Block
108
+ if 'selected_block' in locals() and selected_block != 'All Blocks':
109
  filtered_data = filtered_data[filtered_data['Housing Block'] == selected_block]
110
 
111
  # Filter data based on date range (only for Complaints Over Time visualization)
 
126
 
127
 
128
 
129
+
130
  # Display metrics
131
  col1, col2 = st.columns(2)
132
  with col1:
 
332
  # Plot the data
333
  fig = complaint_pivot.plot(kind='bar', stacked=True, colormap='inferno', figsize=(10, 6)).get_figure()
334
  st.pyplot(fig)
335
+
336
  st.write("""
337
  **What this visualization shows:**
338
  This line chart shows the trend of complaints over time, displaying the number of complaints reported for each day. It helps identify patterns, peaks, and trends in the complaints data.