ralate2 commited on
Commit
8b33a3f
·
verified ·
1 Parent(s): 4b58641

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -17
app.py CHANGED
@@ -72,7 +72,7 @@ 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", "Monthly Trends by Complaint Type",
76
  "Complaints Over Time", "Complaints by Housing Block and Type"
77
  ])
78
 
@@ -124,8 +124,6 @@ if viz_type == "Complaints by Housing Block and Type" and selected_block != 'All
124
  st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selected_year}")
125
 
126
 
127
-
128
-
129
  # Display metrics
130
  col1, col2 = st.columns(2)
131
  with col1:
@@ -214,21 +212,50 @@ elif viz_type == "Geographic Distribution":
214
  # """)
215
 
216
 
217
- # elif viz_type == "Submission Methods":
218
- # st.subheader("Submission Methods Analysis")
219
- # submission_counts = filtered_data['Method Submitted'].value_counts()
220
- # fig, ax = plt.subplots(figsize=(10, 6))
221
- # sns.barplot(x=submission_counts.values, y=submission_counts.index, palette='inferno', ax=ax)
222
- # st.pyplot(fig)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
223
 
224
- # st.write("""
225
- # **What this visualization shows:**
226
- # This bar chart shows the number of complaints submitted via different methods, such as email, phone, online form, etc.
227
- # **Why it's interesting:**
228
- # By analyzing submission methods, we can understand how users prefer to submit complaints and focus on improving the most used channels.
229
- # **Color Scheme:**
230
- # The 'inferno' color palette is used to highlight differences in submission frequency, with darker shades indicating higher submission counts.
231
- # """)
232
 
233
 
234
  # elif viz_type == "Complaints by Disposition":
 
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
 
 
124
  st.header(f"Analysis for {'All Time' if selected_year == 'All Time' else selected_year}")
125
 
126
 
 
 
127
  # Display metrics
128
  col1, col2 = st.columns(2)
129
  with col1:
 
212
  # """)
213
 
214
 
215
+ # Submission Methods Analysis
216
+ elif viz_type == "Submission Methods":
217
+ st.subheader("Submission Methods Analysis")
218
+
219
+ # Allow the user to select the type of chart (Bar or Pie)
220
+ plot_type = st.selectbox("Select Plot Type", options=["Bar Chart", "Pie Chart"])
221
+
222
+ # Get the top 5 submission methods
223
+ submission_counts = filtered_data['Method Submitted'].value_counts().nlargest(5)
224
+ submission_data = submission_counts.reset_index()
225
+ submission_data.columns = ['Submission Method', 'Count']
226
+
227
+ if plot_type == "Bar Chart":
228
+ # Create a bar chart with Seaborn
229
+ fig, ax = plt.subplots(figsize=(10, 6))
230
+ sns.barplot(x=submission_data['Count'], y=submission_data['Submission Method'], palette='inferno', ax=ax)
231
+ st.pyplot(fig)
232
+
233
+ elif plot_type == "Pie Chart":
234
+ # Create an interactive pie chart with Plotly
235
+ fig = px.pie(
236
+ submission_data,
237
+ names='Submission Method',
238
+ values='Count',
239
+ title="Top 5 Submission Methods Distribution",
240
+ color_discrete_sequence=px.colors.inferno,
241
+ labels={"Count": "Number of Complaints", "Submission Method": "Method Submitted"},
242
+ hover_data=['Count']
243
+ )
244
+ fig.update_traces(textinfo='percent+label', hovertemplate='<b>%{label}</b><br>Complaints: %{value}<br>Percentage: %{percent}')
245
+ st.plotly_chart(fig, use_container_width=True)
246
+
247
+ # Updated write-up
248
+ st.write("""
249
+ **What this visualization shows:**
250
+ This chart shows the number of complaints submitted via different methods, such as email, phone, online form, etc., with a focus on the top 5 submission methods.
251
+
252
+ **Why it's interesting:**
253
+ By analyzing submission methods, we can understand how users prefer to submit complaints. This insight helps in focusing efforts on improving the most used channels, ensuring better user engagement.
254
+
255
+ **Color Scheme:**
256
+ The 'inferno' color palette highlights differences in submission frequency, with darker shades representing higher submission counts.
257
+ """)
258
 
 
 
 
 
 
 
 
 
259
 
260
 
261
  # elif viz_type == "Complaints by Disposition":