Data not shown using multiselect

Hi All,

I have used the below code to retrieve data based on the user selection.

container = st.beta_container()
all = st.sidebar.checkbox("Select all")
 
if all:
    selected_options = container.multiselect("Select one or more years:", 
       # ['2016', '2017', '2018', '2019', '2020'], ['2016', '2017', '2018', '2019', '2020'])
else:
   selected_options =  container.multiselect("Select one or more years:", 
    ['2016', '2017', '2018', '2019', '2020'])

show_data = df1[(df1['YEAR_NUMBER']).isin(selected_options)]


is_check = st.sidebar.button("Display Data")
if is_check:
    st.write(show_data)

When the user manually select the ‘Year’ value and click on ‘Display Data’ button it shows the corrects information.

Whereas when he enables the “Select all” checkbox and click on ‘Display Data’ button it does not show any data.

Your inputs will be appreciated.
Thank You.

Hi @SriG, welcome to the Streamlit community!

Are you intentionally commenting out the line in the if all section? Running this bit of code seems to work as expected:

import streamlit as st


container = st.beta_container()
all = st.sidebar.checkbox("Select all")

if all:
    selected_options = container.multiselect(
        "Select one or more years:",
        ["2016", "2017", "2018", "2019", "2020"],
        ["2016", "2017", "2018", "2019", "2020"],
    )
else:
    selected_options = container.multiselect(
        "Select one or more years:", ["2016", "2017", "2018", "2019", "2020"]
    )

#swapped in this since I don't have your data
show_data = "Here's the data"


is_check = st.sidebar.button("Display Data")
if is_check:
    st.write(show_data)

Best,
Randy