I was trying out streamlit searchbox


I wanted to use streamlit selectbox so users can select from a column in the pandas data frame. I have executed the code properly but it takes too long for streamlit to load the option because the total number of entries in the list is huge. Is there any solution to reduce the time or to have a search box kind of feature so that all the options are not loaded into the dropdown box ? Thanks in advance.

Steps to reproduce

Code snippet:

song_list = df['name'].unique()

user_name = st.selectbox('Choose your favourite song here',song_list)

Expected behavior:

It takes too long for the code to process and the drop down menu to appear.

Actual behavior:

I would like to reduce the time it takes for the drop down menu to appear or the drop down menu does not appear and we just get a search bar and it takes less time.

Which one of the two lines of code is taking too long?

I’m not sure how to solve your problem using a selectbox, but instead you could use streamlit aggrid to display the options and return the song the user clicks on

One of the things you could try is β†’

  1. Create a new dataframe with just one column containing df['name'].unique()
  2. Save this dataframe as a feather file.
    (The load times of a feather file is almost half as compared to a CSV)

Depending on your use case, you could consider doing a textbox and just using whatever the user types to filter down the list that is then displayed (probably checking to see if they’ve entered at least 2-3 characters before doing anything). If you wanted to do this β€œlive”, you could use the streamlit-keyup component for this GitHub - blackary/streamlit-keyup: Streamlit text input that returns value on keyup

The second line is taking too much time.

Thank you for this solution. This method reduced the wait time by a lot.

1 Like

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