Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import streamlit as st | |
def display_dataframe(df, drop_cols, data_url, search_id=True, status=False, for_help_requests=False, show_link=True): | |
"""Display the dataframe in a table""" | |
col_1, col_2 = st.columns([1, 1]) | |
# has df's first row | |
df_hash = hash(df.iloc[0].to_string()) | |
with col_1: | |
query = st.text_input("🔍 Search for information / بحث عن المعلومات", key=f"query_{df_hash}") | |
with col_2: | |
if search_id: | |
id_number = st.number_input( | |
"🔍 Search for an id / بحث عن رقم", | |
min_value=0, | |
# max_value=len(df), | |
value=0, | |
step=1, | |
key=f"id_{df_hash}", | |
) | |
if status: | |
selected_status = st.selectbox( | |
"🗓️ Status / حالة", ["all / الكل", "Done / تم", "Planned / مخطط لها"], key=f"status_{df_hash}" | |
) | |
if query: | |
# Filtering the dataframe based on the query | |
mask = df.apply(lambda row: row.astype(str).str.contains(query.lower(), case=False).any(), axis=1) | |
display_df = df[mask] | |
else: | |
display_df = df | |
if search_id and id_number: | |
display_df = display_df[display_df["id"] == id_number] | |
display_df = display_df.drop(drop_cols, axis=1) | |
if status: | |
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" | |
if selected_status == "Done / تم": | |
display_df = display_df[display_df[target] == "Intervention déjà passée / Past intevention"] | |
elif selected_status == "Planned / مخطط لها": | |
display_df = display_df[display_df[target] != "Intervention déjà passée / Past intevention"] | |
st.dataframe(display_df, height=500) | |
# Original link to the Google Sheet | |
if show_link: | |
st.markdown( | |
f"To view the full Google Sheet for advanced filtering go to: {data_url} **لعرض الورقة كاملة، اذهب إلى**" | |
) | |
# if we want to check hidden contact information | |
if for_help_requests: | |
st.markdown( | |
"We are hiding contact information to protect the privacy of the victims. If you are an NGO and want to contact the victims, please contact us at [email protected]", | |
) | |
st.markdown( | |
""" | |
<div style="text-align: left;"> | |
<a href="mailto:[email protected]">[email protected]</a> نحن نخفي معلومات الاتصال لحماية خصوصية الضحايا. إذا كنت جمعية وتريد الاتصال بالضحايا، يرجى الاتصال بنا على | |
</div> | |
""", | |
unsafe_allow_html=True, | |
) | |