select_box on_change requires a change, so selecting the first item (the default) in the list does not trigger the callback. So the user has to select something else first, then select back to the first item in the list.
How can I make it possible for the user to just simply select the first item in the list?
Steps to reproduce
Code snippet:
add code here
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
Explain what you expect to happen when you run the code above.
Actual behavior:
Explain the undesired behavior or error you see when you run the code above.
If you’re seeing an error message, share the full contents of the error message here.
Debug info
Streamlit version: (get it with $ streamlit version)
Python version: (get it with $ python --version)
Using Conda? PipEnv? PyEnv? Pex?
OS version:
Browser version:
Requirements file
Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.
Links
Link to your GitHub repo:
Link to your deployed app:
Additional information
If needed, add any other context about the problem here.
Hi @Matthew_King, here’s a simple solution: suppose your selectbox options are [‘a’, ‘b’, ‘c’]. Why not change them to [‘’, ‘a’, ‘b’, ‘c’]. That way, your selectbox will have a default blank when it first loads. And the user would need to choose your 2nd item, which you consider to be as your first.
Additionally, by doing this, you get to know that the user explicitly chose an option, and what is being seen in the selectbox on first load, is not what the streamlit widget naturally put out.
That is a workaround. But it still means the user cannot select the default value set by the index arg, because that is not a change. This seems very counter intuitive and I was wondering if I was missing something.
I agree with @Shawn_Pereira and that’s how I usually handle this kind of case. Either default to an invalid choice so it’s forced, or default to a value with all the rest of the page consistent as if that default value had just been selected.
Would it work better for you to use a form and tie the action to a submit button? Or even to add a “confirm” button on the page without a form to have an intuitive way for the user to progress?
What event are you triggering in your callback that doesn’t align with the page loading with that default value already selected?
Its the same nested lists flow we are talking about on the other thread. User selects from a list of Customers, which then determines a list of Orchards that they can pick from, which then determines a list of Blocks they can pick from. Same logic if it were selecting State, then City, then Block,
That they cannot select the default, and also I have to write a special case using a button instead of a selectbox if there happens to be only 1 element in the list, just seems off to me. It smells like I am missing something obvious.
Hi @blackary, the No-Default Selectbox seems to be better than the native Streamlit selectbox in terms of functionality. Is there a reason it is not within Streamlit, but a part of the extras?
Other widgets (such as the date widget) need to have this functionality. Date widgets need to default to a none / blank value, rather than the current date. Without this, non-mandatory date widgets in a data app become effectively useless.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.