nouamanetazi HF staff loubnabnl HF staff commited on
Commit
5fe0186
1 Parent(s): 78ad925

Use streamlit dataframe instead of displaying google sheet (with options for filtering) (#13)

Browse files

- Use streamlit dataframe instead of displaying google sheet (with options for filtering) (bfa922465c76b92ce14b837ee2e0f7bc5a264268)


Co-authored-by: Loubna Ben Allal <[email protected]>

Files changed (1) hide show
  1. app.py +76 -9
app.py CHANGED
@@ -128,18 +128,67 @@ def show_requests(filtered_df, m):
128
  ).add_to(m)
129
 
130
 
131
- def display_google_sheet_tables():
 
132
  """Display the google sheet tables for requests and interventions"""
133
- st.subheader("📝 **Table of requests / جدول الطلبات**")
134
  st.markdown(
135
- f"""<iframe src="{REQUESTS_URL}" width="100%" height="600px"></iframe>""",
136
  unsafe_allow_html=True,
137
  )
138
 
139
- st.subheader("📝 **Table of interventions / جدول التدخلات**")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  st.markdown(
141
- f"""<iframe src="{INTERVENTIONS_URL}" width="100%" height="600px"></iframe>""",
142
- unsafe_allow_html=True,
143
  )
144
 
145
 
@@ -236,9 +285,27 @@ show_requests(filtered_df, m)
236
 
237
  st_data = st_folium(m, use_container_width=True)
238
 
239
- # Google Sheet Tables
240
- display_google_sheet_tables()
241
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  # Submit an id for review
243
  id_review_submission()
244
 
 
128
  ).add_to(m)
129
 
130
 
131
+
132
+ def display_google_sheet_tables(data_url):
133
  """Display the google sheet tables for requests and interventions"""
 
134
  st.markdown(
135
+ f"""<iframe src="{data_url}" width="100%" height="600px"></iframe>""",
136
  unsafe_allow_html=True,
137
  )
138
 
139
+
140
+ def display_dataframe(df, drop_cols, data_url, search_id=True, status=False):
141
+ """Display the dataframe in a table"""
142
+ col_1, col_2 = st.columns([1, 1])
143
+
144
+ with col_1:
145
+ query = st.text_input(
146
+ "🔍 Search for information / بحث عن المعلومات",
147
+ key=f"search_requests_{int(search_id)}",
148
+ )
149
+ with col_2:
150
+ if search_id:
151
+ id_number = st.number_input(
152
+ "🔍 Search for an id / بحث عن رقم",
153
+ min_value=0,
154
+ max_value=len(filtered_df),
155
+ value=0,
156
+ step=1,
157
+ )
158
+ if status:
159
+ selected_status = st.selectbox(
160
+ "🗓️ Status / حالة",
161
+ ["all / الكل", "Done / تم", "Planned / مخطط لها"],
162
+ key="status",
163
+ )
164
+
165
+ if query:
166
+ # Filtering the dataframe based on the query
167
+ mask = df.apply(lambda row: row.astype(str).str.contains(query).any(), axis=1)
168
+ display_df = df[mask]
169
+ else:
170
+ display_df = df
171
+
172
+ display_df = display_df.drop(drop_cols, axis=1)
173
+
174
+ if search_id and id_number:
175
+ display_df = display_df[display_df["id"] == id_number]
176
+
177
+ if status:
178
+ target = "Pouvez-vous nous préciser si vous êtes déjà intervenus ou si vous prévoyez de le faire | Tell us if you already made the intervention, or if you're planning to do it"
179
+ if selected_status == "Done / تم":
180
+ display_df = display_df[
181
+ display_df[target] == "Intervention déjà passée / Past intevention"
182
+ ]
183
+
184
+ elif selected_status == "Planned / مخطط لها":
185
+ display_df = display_df[
186
+ display_df[target] != "Intervention déjà passée / Past intevention"
187
+ ]
188
+
189
+ st.dataframe(display_df, height=500)
190
  st.markdown(
191
+ f"To view the full Google Sheet for advanced filtering go to: {data_url} **لعرض الورقة كاملة، اذهب إلى**"
 
192
  )
193
 
194
 
 
285
 
286
  st_data = st_folium(m, use_container_width=True)
287
 
288
+ st.subheader("📝 **Table of requests / جدول الطلبات**")
289
+ # Requests table
290
+ drop_cols = [
291
+ "(عند الامكان) رقم هاتف شخص موجود في عين المكان",
292
+ "الرجاء الضغط على الرابط التالي لمعرفة موقعك إذا كان متاحا",
293
+ "GeoStamp",
294
+ "GeoCode",
295
+ "GeoAddress",
296
+ "Status",
297
+ ]
298
+ display_dataframe(filtered_df, drop_cols, REQUESTS_URL, search_id=True)
299
+
300
+ # Interventions table
301
+ st.subheader("📝 **Table of interventions / جدول التدخلات**")
302
+ display_dataframe(
303
+ interventions_df,
304
+ ["Informations de Contact | Contact Information"],
305
+ INTERVENTIONS_URL,
306
+ search_id=False,
307
+ status=True,
308
+ )
309
  # Submit an id for review
310
  id_review_submission()
311