Hello, I have created an app which references and loads a dataframe from an excel file in my local drive. I use streamlit to manipulate this dataframe through filtering, which is selected from sidebar multiselect inputs based on the columns of my df.
When the streamlit page initially loads, the dataframe is empty as no filtering is selected, and all three filtering options have been filled with at least 1 input.
Is there a way to adjust my code so that when the page initially loads the df will be illustrated fully (when no filters are selected) and will be adjusted accordingly once the filtering multiselect options are populated?
Here is my code so far:
LIST_OF_OWNERS = sorted(df['Owner'].unique())
LIST_OF_COUNTRIES = sorted(df['Country'].unique())
LIST_OF_CLIENTS = sorted(df['Client'].unique())

ref_owner_state = get_state()
 
if st.sidebar.button('Add all Owners'):
    owner_filter = st.sidebar.multiselect('Select owner',
    LIST_OF_OWNERS,
    default=LIST_OF_OWNERS)
else:
    owner_filter = st.sidebar.multiselect('Select owner',
    LIST_OF_OWNERS,
    default=ref_owner_state.previous_owners_selected)

ref_owner_state.previous_owners_selected = owner_filter
ref_owner_state.sync()


ref_country_state = get_state()

if st.sidebar.button('Add All Countries'):
    country_filter = st.sidebar.multiselect('Select a country',
    LIST_OF_COUNTRIES,
    default=LIST_OF_COUNTRIES)
else:
    country_filter = st.sidebar.multiselect('Select a country',
    LIST_OF_COUNTRIES,
    default=ref_country_state.previous_countries_selected)

ref_country_state.previous_countries_selected = country_filter
ref_country_state.sync()


ref_client_state = get_state()

if st.sidebar.button('Add All Clients'):
    client_filter = st.sidebar.multiselect('Select a client',
    LIST_OF_CLIENTS,
    default=LIST_OF_CLIENTS)
else:
    client_filter = st.sidebar.multiselect('Select a client',
    LIST_OF_CLIENTS,
    default=ref_client_state.previous_clients_selected)

ref_client_state.previous_clients_selected = client_filter
ref_client_state.sync()

selected_df = df[df['Owner'].isin(owner_filter) & df['Country'].isin(country_filter) & df['Client'].isin(client_filter)]

st.dataframe(selected_df )