The issue i have is with the slider (double slider) functionality. I would like to have it display all the options within it’s range, instead of the option that is selected. For eg,
color = st.select_slider(
'Select a color of the rainbow',
options=['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'])
st.write('My favorite color is', color)
Expected behavior:
When i run this run this code, it prints ‘My favourite color is…’. It gives a different color depending on the color where the slider mark pointer is. I would like it to give the range of colors instead. For example, if the slider pointer is at green, it should say ‘my favourite color is red, orange, yellow and green.’
This is because the actual code only prints ‘my favourite color is green’ if green is where the slider pointer is and i want to change that.
value (a supported type or a tuple/list of supported types or None)
The value of the slider when it first renders. If a tuple/list of two values is passed here, then a range slider with those lower and upper bounds is rendered. For example, if set to (1, 10) the slider will have a selectable range between 1 and 10. Defaults to first option.
When passing the tuple, you only get back the lower and upper bounds, not all the elements in between. For that, you’ll need some additional trick.
import streamlit as st
list_colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
single_color = st.select_slider(
'Select a color of the rainbow',
options= list_colors,
value='orange')
st.write('My favorite color is', single_color)
import streamlit as st
list_colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
two_colors = st.select_slider(
'Select a color of the rainbow',
options= list_colors,
value=('orange','blue'))
st.write('My favorite color is', two_colors)
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.