File size: 2,909 Bytes
597fb2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

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,
        )