Multiselect input Interface should generated when user click on button

Summary

I am creating dashboard using streamlit. For that I have given some option to user, Once user Click on provided button then only I want to showcase multiselect option to user.

but when Iā€™m trying to use multiselect option once user press button

if st.button('Load Data'):

without above list code is working fine for me.

Steps to reproduce

Code snippet:

import streamlit as st
import pandas as pd

st.set_page_config(page_title=" Review", layout='wide', page_icon="šŸ“ˆ", initial_sidebar_state="expanded")
st.sidebar.header("Review")

df = pd.read_csv(r'C:\test.csv')

# if st.button('Load Data'):

item = st.sidebar.multiselect(label= 'Select The item',
                            options=df['item'].unique(),
                            default=df['item'].unique())

city = st.sidebar.multiselect(label='Select city',
                        options=df['city'].unique(),
                        default=df['city'].unique())

Summary_Table_1 = df.query('item == @item & city == @city')

st.dataframe(Summary_Table_1)

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:

This code should work when user press the button once. And after pressing that button user able to use multiselect options

Actual behavior:

Currently, User able to see multi select option after clicking on button but Once they try to apply filter on multiselect from front screen everying get reset

Debug info

  • Streamlit version: latest version
  • Python version: 3.9
  • Using Conda? no
  • OS version: Window 11
  • Browser version: EDGE 114.0.1823.67

Let me how can I solve above issue.
Thanks for help!

Hi @Ghanshyam

Session state would help to solve this issue. Please see how to use using the following resources:

A conceptual overview of Session State in Streamlit is provided in the following video:

Hope this helps!

Best regards,
Chanin