Hi everyone ! First thanks for the streamlit package that is very useful !
I just face a problem when I develop my streamlit application with the st.button.
I explain :
I get some “filters” that the user can apply as his choice. The first filter is the tab selecting (three tabs which provide differents data).
When the user chooses a tab, then he can choose some filters. But with the st.button, when the user choose another filter after the tab, the button is “restarted” and he goes back to the welcome page.
Is it possible to keep a button activate as long as another button is not selectionned ?
For illustrate it, look at this picture :
In red : the tab selection
In blue : the filters selection
When I click on a tab, I run to some visualisation but then when I click to a filter, the application restart because filter button is not keeping activate.
Thanks a lot for read me, I hope someone can help !
Buttons set their value to True only in the instant they are clicked . After that, their value goes back to False.
In your use case you would be advised to use st.radio. Radio buttons lay out vertically, so that might not suit you. So, instead use st.checkbox in multiple columns. Then set and hold the value state of the checkboxes in st.session_state.
See “multi-page-app-with-session-state” for inspiration. If you want the page to reset, then use st.experimental_rerun to run the app from the top but still preserving the set states.
I just come to you to say thanks to your answer. Like you say, I have to layout my buttons horizontally. With a little search in addition with you answer, I find a solution than can satisfy me !
So I use the radio button, but with a Widget style parameter. Just to inform you, if you apply this :
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.