Hi! I’m new to Streamlit, and I’m doing my first website using this package. I have a few basic questions regarding, formatting the filters: slider, text_input and selectbox.
How do I hide the static label of slider? Like this:
countries = sorted(players['Country'].unique())
if 'All' not in countries:
countries.insert(0, 'All')
selected_country = st.sidebar.selectbox('Country', options=countries, index=countries.index(default_selected_country) if not reset_button else 0, key="key_country")
I’ve simplified your example so that the snippet is executable for everyone. The CSS applies to all sliders in your app. You can add scoping to make it apply only to sliders in your sidebar if you want.
Here’s the extra bit for st.selectbox, but I generally recommend against centering like this. As you’ll note with a selectbox, the extra UI element (the down arrow) messes with the concept of “center.” That adds extra tweaks to make the label and the internals both look the same. This in turn makes it more fragile and likely to appear slightly off. The left justification that is standard with Streamlit apps is protective against misalignment given the various screens and resolutions that people have.
import streamlit as st
countries = ["Alpha", "Beta", "Gamma", "Delta"]
if 'All' not in countries:
countries.insert(0, 'All')
selected_country = st.sidebar.selectbox('Country', options=countries, key="key_country")
css = """
<style>
.stSelectbox [data-baseweb="select"] > div > div > div:first-child {
display: block;
width: 100%;
text-align: center;
padding-left: 32px;
}
[data-testid="stVirtualDropdown"] li {
text-align: center;
}
.stSelectbox label {
display: block;
text-align: center;
}
</style>
"""
st.markdown(css, unsafe_allow_html=True)
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.