Unable to change default value of multiselect() on selection with polars


I am unable to select options other than default option of multiselect(). PS - I am using polars to process the data for efficiency. I have also tried with selectbox but was getting some issues there as well.
(I am reposting this as somehow it got deleted earlier).


Line number: 46 for the respective code chunk.

Steps to reproduce

Code snippet:

with st.sidebar:
    State_List = df.lazy().select(pl.col('State')).unique().collect().to_series().to_list()

    # State_Selected = st.selectbox(label="Select State",
    #                               options = State_List)

    State_Selected = st.multiselect(label="Select State",
                                    options = State_List,
                                    default = ["Uttar Pradesh"], # Delhi West Bengal  
                                    # default = State_List[-1],

Expected behavior:

This is the first filter option on the app and user should be a able to select any one option from it which also creates an input for the second filter multiselect of the app and they both are used to subset the data.

Actual behavior:

It is not letting me use any other option in the first multiselect() filter.

Debug info


Conda information

 active environment : None
   user config file : C:\Users\vinee\.condarc

populated config files : C:\Users\vinee.condarc
conda version : 23.3.1
conda-build version : 3.24.0
python version : 3.9.16.final.0
virtual packages : __archspec=1=x86_64
base environment : C:\Users\vinee\anaconda3 (writable)
conda av data dir : C:\Users\vinee\anaconda3\etc\conda
conda av metadata url : None

           platform : win-64
         user-agent : conda/23.3.1 requests/2.28.1 CPython/3.9.16 Windows/10 Windows/10.0.19045
      administrator : False
         netrc file : None
       offline mode : False

What are you trying to accomplish using multiselect with max_selections=1?

I was getting an issue with st.selectbox() so I used multiselect instead

Just by changing the 1st multiselect filter to_pandas instead of polars lazy eval this worked. I only had to change the below line of code:


State_List = df.lazy().select(pl.col('State')).unique().collect().to_series().to_list()

to: State_List = df.collect().to_pandas()["State"].unique().tolist()

I think it will also work with st.selectbox() now.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.