ralate2 commited on
Commit
8666827
·
verified ·
1 Parent(s): fbaad9b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -3
app.py CHANGED
@@ -72,6 +72,63 @@ def load_and_clean_data():
72
  data = load_and_clean_data()
73
 
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  # Sidebar for controls
76
  st.sidebar.header("Dashboard Controls")
77
 
@@ -80,9 +137,9 @@ 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")
@@ -97,7 +154,11 @@ if viz_type == "Complaints Over Time":
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():
@@ -130,6 +191,7 @@ if viz_type in ["Complaints by Housing Block and Type", "Complaints by Housing B
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:
 
72
  data = load_and_clean_data()
73
 
74
 
75
+ # # Sidebar for controls
76
+ # st.sidebar.header("Dashboard Controls")
77
+
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:
90
+ # selected_year = 'All Time' # Default to 'All Time' if visualization doesn't require year
91
+
92
+ # # Date Range Selector for Complaints Over Time (only show when Complaints Over Time is selected)
93
+ # if viz_type == "Complaints Over Time":
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
107
+ # if selected_year != 'All Time':
108
+ # filtered_data = data[data['Year Reported'] == selected_year]
109
+ # else:
110
+ # filtered_data = data
111
+
112
+ # # Further filtering by Housing Block
113
+ # if 'selected_block' in locals() and selected_block != 'All Blocks':
114
+ # filtered_data = filtered_data[filtered_data['Housing Block'] == selected_block]
115
+
116
+ # # Filtering data based on date range (only for Complaints Over Time visualization)
117
+ # if viz_type == "Complaints Over Time":
118
+ # filtered_data_time = filtered_data[
119
+ # (filtered_data['Date Reported'] >= pd.to_datetime(start_date)) &
120
+ # (filtered_data['Date Reported'] <= pd.to_datetime(end_date))
121
+ # ]
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
  # Sidebar for controls
133
  st.sidebar.header("Dashboard Controls")
134
 
 
137
  "Complaint Types", "Geographic Distribution", "Complaints by Disposition", "Submission Methods",
138
  "Monthly Trends by Complaint Type", "Complaints Over Time", "Complaints by Housing Block and Type",
139
  "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)"
140
+ ], key="viz_type_select")
141
 
142
+ # Remove the year selection when certain visualizations are selected
143
  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)"]:
144
  year_options = ['All Time'] + sorted(data['Year Reported'].unique().tolist())
145
  selected_year = st.sidebar.selectbox("Select Year", options=year_options, key="year_select")
 
154
  # Dropdown for Housing Block (only show when Complaints by Housing Block and Type or the updated version is selected)
155
  if viz_type in ["Complaints by Housing Block and Type", "Complaints by Housing Block and Type (Incorporating Suggestions Based on Professor's Feedback)"]:
156
  block_options = ['All Blocks'] + sorted(data['Housing Block'].unique().tolist())
157
+ selected_block = st.sidebar.selectbox(
158
+ "Select Housing Block",
159
+ options=block_options,
160
+ key=f"block_select_{viz_type}" # Unique key for each visualization
161
+ )
162
 
163
  # Ensuring selected_block is only used if defined
164
  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():
 
191
  st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selected_year}")
192
 
193
 
194
+
195
  # Displaying metrics
196
  col1, col2 = st.columns(2)
197
  with col1: