I’m starting out with Streamlit and I’m loving it. Such a refreshingly different paradigm!
But here a question: I use multiple st.sliders for input values to my graphs. It would be nice to reset the sliders to some special predetermined positions when I press some button.
You can’t (as far as I can tell) change them programatically. You can set a default value, but since the widget key will change if you change this it causes some problems if you use buttons. Using a selectbox looks like it gets around this (as that’s then persistent):
Thanks @Ian_Calvert. Interesting approach. Doesn’t get 100% though where I want to get to: With a button I have the problem that I have to put something in the else branch (Button not pressed), and this then will sometimes reset the slider…
Also, another goal is to make two sliders depending on each other: A Start date slider and a End date slider. Both sliders can slide over the whole date range and then redraw each other so that the start date slider is always “left” of the end date slider. - I guess that’s not possible, right?
With a button I have the problem that I have to put something in the else branch (Button not pressed), and this then will sometimes reset the slider…
Yeah buttons are only true on the next run of the code, using them needs to be done quite carefully so I prefer stateful components. Particularly when they affect others.
If you’re explicitly after a slider, then you can just pass two values into the slider for the default value and it becomes a range slider. You might need to do some conversion to get dates though as I think it only supports numeric values.
Otherwise no, I don’t think you can make two sliders depend on each other
Thanks @Ian_Calvert for this interesting approach. I tried to use this approach inside a st.form, before pressing the Submit button.
This approach is not working inside a form. Could you please help me with this issue?
Thanks
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.