File size: 4,576 Bytes
8b9797b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d747029
 
 
 
 
 
 
 
 
 
 
 
 
8b9797b
 
 
 
 
 
 
 
 
 
 
 
 
d747029
 
8b9797b
 
 
 
 
 
 
 
d747029
8b9797b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d747029
 
87e117e
8b9797b
d747029
 
 
 
 
 
 
 
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import streamlit as st
import pandas as pd

# 1. Loading the dataset
df = pd.read_excel("data/table.xlsx")

# 2. Preprocessing the dataset
df["Bionic prototype"] = df["Bionic prototype"].str.strip()
df["Materials"] = df["Materials"].str.split(";").apply(lambda x: [material.strip() for material in x])
df["Method"] = df["Method"].str.split(";").apply(lambda x: [method.strip() for method in x])
df["Multifunction"] = df["Multifunction"].str.split(";").apply(lambda x: [multifunction.strip() for multifunction in x])

# 3. Saving the processed dataset
# df.to_excel("data/filtered_table.xlsx", index=False)

# 4. Extracting a unique list for each column
bionic_prototype_list = df["Bionic prototype"].unique()
method_list = df["Method"].explode().unique()
multifunction_list = df["Multifunction"].explode().unique()
bionic_prototype_list.sort()
method_list.sort()
multifunction_list.sort()

ordered_multifunction_list = ["Antifogging", "Self-cleaning", "Antireflective", "Antibacterial", "Anti-icing",
                              "Antiwetting", "Large FOV", "Fast motion detection", "Structural color",
                              "Droplet directional migration", "Anti-drag", "Water collection",
                              "Self-propelled actuator"]
other_multifunction_list = [x for x in multifunction_list if x not in ordered_multifunction_list]
ordered_multifunction_list.extend(other_multifunction_list)


def show_res_link(row_idx):
    res_link = df.iloc[row_idx]['Res link']
    st.sidebar.info(f'Resource Link: {res_link}')


with st.sidebar:
    st.slider(
        label="Search results limit",
        min_value=1,
        max_value=50,
        value=20,
        step=1,
        key="limit",
        help="Limit the number of search results",
    )

    st.multiselect(
        label="Display columns",
        options=["Bionic prototype", "Multifunction", "Method", "Materials", "Res link"],
        default=["Bionic prototype", "Multifunction", "Method", "Materials", "Res link"],
        help="Select columns to display in the search results",
        key="display_columns",
    )

st.title("Bionic Path Selection")

st.multiselect(
    label="Multifunction",
    options=ordered_multifunction_list,
    default=[],
    help="Select the multifunction to display in the search results",
    placeholder="Select the multifunction to display in the search results",
    key="multifunction_option"
)

st.session_state.disabled = False if len(st.session_state.multifunction_option) > 0 else True

left_col, right_col = st.columns(2)
with left_col:
    st.selectbox(
        label="Bionic prototype",
        options=bionic_prototype_list,
        help="Select the bionic prototype to display in the search results",
        placeholder="Select the bionic prototype to display in the search results",
        index=None,
        key="bionic_prototype_option",
        disabled=st.session_state.disabled
    )
with right_col:
    st.multiselect(
        label="Method",
        options=method_list,
        default=[],
        help="Select the method to display in the search results",
        placeholder="Select the method to display in the search results",
        key="method_option",
        disabled=st.session_state.disabled
    )

search = st.button("Search")
if search:
    multifunction_option = st.session_state.multifunction_option
    bionic_prototype_option = st.session_state.bionic_prototype_option
    method_option = st.session_state.method_option

    # Filter the multifunction column
    filtered_df = df[
        df["Multifunction"].apply(lambda x: all(multifunction in x for multifunction in multifunction_option))]
    # Filter the bionic prototype column
    filtered_df = filtered_df[filtered_df["Bionic prototype"] == bionic_prototype_option] \
        if (bionic_prototype_option is not None and not st.session_state.disabled and not filtered_df.empty) \
        else filtered_df
    # Filter the method column
    filtered_df = filtered_df[filtered_df["Method"].apply(lambda x: any(method in x for method in method_option))] \
        if (len(method_option) > 0 and not st.session_state.disabled and not filtered_df.empty) \
        else filtered_df
    # Reset the index
    filtered_df = filtered_df.reset_index(drop=True)
    filtered_df.index = range(1, len(filtered_df)+1)

    st.dataframe(
        filtered_df[st.session_state.display_columns].head(st.session_state.limit),
        column_config={
            "Res link": st.column_config.LinkColumn(
                "Resource", display_text=None
            )
        }
    )