ralate2 commited on
Commit
f6bdcdc
·
verified ·
1 Parent(s): c1925f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -10
app.py CHANGED
@@ -67,35 +67,95 @@ def load_and_clean_data():
67
  # Load the data
68
  data = load_and_clean_data()
69
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  # Sidebar for controls
71
  st.sidebar.header("Dashboard Controls")
72
 
73
  # First, define the visualization type (viz_type) selection
74
  viz_type = st.sidebar.selectbox("Select Visualization", [
75
- "Complaint Types", "Geographic Distribution", "Complaints by Disposition", "Submission Methods","Monthly Trends by Complaint Type",
76
- "Complaints Over Time", "Complaints by Housing Block and Type"
77
  ])
78
 
79
  # Remove the year selection when certain visualizations are selected
80
  if viz_type not in ["Complaints Over Time", "Complaints by Housing Block and Type"]:
81
  year_options = ['All Time'] + sorted(data['Year Reported'].unique().tolist())
82
- selected_year = st.sidebar.selectbox("Select Year", options=year_options)
83
  else:
84
  selected_year = 'All Time' # Default to 'All Time' if visualization doesn't require year
85
 
86
  # Date Range Selector for Complaints Over Time (only show when Complaints Over Time is selected)
87
  if viz_type == "Complaints Over Time":
88
- start_date = st.sidebar.date_input("Start Date", pd.to_datetime("2020-01-01"))
89
- end_date = st.sidebar.date_input("End Date", pd.to_datetime("2024-12-31"))
90
-
91
- # Allow the user to select the type of chart (Bar or Pie) for Submission Methods
92
- if viz_type == "Submission Methods":
93
- plot_type = st.sidebar.selectbox("Select Plot Type", options=["Bar Chart", "Pie Chart"])
94
 
95
  # Dropdown for Housing Block (only show when Complaints by Housing Block and Type is selected)
96
  if viz_type == "Complaints by Housing Block and Type":
97
  block_options = ['All Blocks'] + sorted(data['Housing Block'].unique().tolist())
98
- selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options)
 
 
 
 
99
 
100
  # Ensure selected_block is only used if defined
101
  if viz_type == "Complaints by Housing Block and Type" and 'selected_block' not in locals():
@@ -128,6 +188,7 @@ if viz_type == "Complaints by Housing Block and Type" and selected_block != 'All
128
  st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selected_year}")
129
 
130
 
 
131
  # Display metrics
132
  col1, col2 = st.columns(2)
133
  with col1:
 
67
  # Load the data
68
  data = load_and_clean_data()
69
 
70
+ # # Sidebar for controls
71
+ # st.sidebar.header("Dashboard Controls")
72
+
73
+ # # First, define the visualization type (viz_type) selection
74
+ # viz_type = st.sidebar.selectbox("Select Visualization", [
75
+ # "Complaint Types", "Geographic Distribution", "Complaints by Disposition", "Submission Methods","Monthly Trends by Complaint Type",
76
+ # "Complaints Over Time", "Complaints by Housing Block and Type"
77
+ # ])
78
+
79
+ # # Remove the year selection when certain visualizations are selected
80
+ # if viz_type not in ["Complaints Over Time", "Complaints by Housing Block and Type"]:
81
+ # year_options = ['All Time'] + sorted(data['Year Reported'].unique().tolist())
82
+ # selected_year = st.sidebar.selectbox("Select Year", options=year_options)
83
+ # else:
84
+ # selected_year = 'All Time' # Default to 'All Time' if visualization doesn't require year
85
+
86
+ # # Date Range Selector for Complaints Over Time (only show when Complaints Over Time is selected)
87
+ # if viz_type == "Complaints Over Time":
88
+ # start_date = st.sidebar.date_input("Start Date", pd.to_datetime("2020-01-01"))
89
+ # end_date = st.sidebar.date_input("End Date", pd.to_datetime("2024-12-31"))
90
+
91
+ # # Allow the user to select the type of chart (Bar or Pie) for Submission Methods
92
+ # if viz_type == "Submission Methods":
93
+ # plot_type = st.sidebar.selectbox("Select Plot Type", options=["Bar Chart", "Pie Chart"])
94
+
95
+ # # Dropdown for Housing Block (only show when Complaints by Housing Block and Type is selected)
96
+ # if viz_type == "Complaints by Housing Block and Type":
97
+ # block_options = ['All Blocks'] + sorted(data['Housing Block'].unique().tolist())
98
+ # selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options)
99
+
100
+ # # Ensure selected_block is only used if defined
101
+ # if viz_type == "Complaints by Housing Block and Type" and 'selected_block' not in locals():
102
+ # selected_block = 'All Blocks' # Default to 'All Blocks' if no selection made
103
+
104
+ # # Filter data based on selected year
105
+ # if selected_year != 'All Time':
106
+ # filtered_data = data[data['Year Reported'] == selected_year]
107
+ # else:
108
+ # filtered_data = data
109
+
110
+ # # Further filter by Housing Block
111
+ # if 'selected_block' in locals() and selected_block != 'All Blocks':
112
+ # filtered_data = filtered_data[filtered_data['Housing Block'] == selected_block]
113
+
114
+ # # Filter data based on date range (only for Complaints Over Time visualization)
115
+ # if viz_type == "Complaints Over Time":
116
+ # filtered_data_time = filtered_data[
117
+ # (filtered_data['Date Reported'] >= pd.to_datetime(start_date)) &
118
+ # (filtered_data['Date Reported'] <= pd.to_datetime(end_date))
119
+ # ]
120
+ # else:
121
+ # filtered_data_time = filtered_data
122
+
123
+ # # Filter data based on selected housing block (only for Complaints by Housing Block visualization)
124
+ # if viz_type == "Complaints by Housing Block and Type" and selected_block != 'All Blocks':
125
+ # filtered_data_time = filtered_data_time[filtered_data_time['Housing Block'] == selected_block]
126
+
127
+ # # Header for selected year
128
+ # st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selected_year}")
129
+
130
  # Sidebar for controls
131
  st.sidebar.header("Dashboard Controls")
132
 
133
  # First, define the visualization type (viz_type) selection
134
  viz_type = st.sidebar.selectbox("Select Visualization", [
135
+ "Complaint Types", "Geographic Distribution", "Complaints by Disposition", "Submission Methods",
136
+ "Monthly Trends by Complaint Type", "Complaints Over Time", "Complaints by Housing Block and Type"
137
  ])
138
 
139
  # Remove the year selection when certain visualizations are selected
140
  if viz_type not in ["Complaints Over Time", "Complaints by Housing Block and Type"]:
141
  year_options = ['All Time'] + sorted(data['Year Reported'].unique().tolist())
142
+ selected_year = st.sidebar.selectbox("Select Year", options=year_options, key="year_select")
143
  else:
144
  selected_year = 'All Time' # Default to 'All Time' if visualization doesn't require year
145
 
146
  # Date Range Selector for Complaints Over Time (only show when Complaints Over Time is selected)
147
  if viz_type == "Complaints Over Time":
148
+ start_date = st.sidebar.date_input("Start Date", pd.to_datetime("2020-01-01"), key="start_date")
149
+ end_date = st.sidebar.date_input("End Date", pd.to_datetime("2024-12-31"), key="end_date")
 
 
 
 
150
 
151
  # Dropdown for Housing Block (only show when Complaints by Housing Block and Type is selected)
152
  if viz_type == "Complaints by Housing Block and Type":
153
  block_options = ['All Blocks'] + sorted(data['Housing Block'].unique().tolist())
154
+ selected_block = st.sidebar.selectbox("Select Housing Block", options=block_options, key="block_select")
155
+
156
+ # Allow the user to select the type of chart (Bar or Pie) for Submission Methods
157
+ if viz_type == "Submission Methods":
158
+ plot_type = st.sidebar.selectbox("Select Plot Type", options=["Bar Chart", "Pie Chart"], key="plot_type_select")
159
 
160
  # Ensure selected_block is only used if defined
161
  if viz_type == "Complaints by Housing Block and Type" and 'selected_block' not in locals():
 
188
  st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selected_year}")
189
 
190
 
191
+
192
  # Display metrics
193
  col1, col2 = st.columns(2)
194
  with col1: