Hi!
Is there any way to change the default color blue of a progress bar?
I want it to change to red or yellow but couldn’t find any way to do it.
Thanks in advance
Hi!
Is there any way to change the default color blue of a progress bar?
I want it to change to red or yellow but couldn’t find any way to do it.
Thanks in advance
Hey @Jose_Diaz, Welcome to the community !
You can use this for now,
import streamlit as st
from time import sleep
st.markdown("""
<style>
.stProgress .st-bo {
background-color: green;
}
</style>
""", unsafe_allow_html=True)
progress = st.progress(0)
for i in range(100):
progress.progress(i)
sleep(0.1)
The support for theming is in development, so you can expect it to be much more straight forward in future !
Hope it helps !
Thank you so much!
can i ask any documentation of it .
cant find any details in
thanks
Jeff
Hi @apex_yu,
Its not documented.
The code just overrides the CSS class .st-bo’s background color property for progressbars ( which has CSS class named .stProgress ). One way to figure this out is by just looking at chrome dev tools’ inspect element.
Attaching a screenshot for reference.
Hope it helps
thanks
Hi @ash2shukla,
there’s a problem with your solution: As far as I understand it, streamlit assigns CSS classes like .st-bo
dynamically during runtime (I assume based on a grid layout), and your component is not necessarily guaranteed to get the same class each time.
So, your solution can work if the layout is static/looks the same at each run (but even then the class is probably not .st-bo
; you have to look it up through the dev tools, as you pointed out) but it breaks for more complex layouts that you change during runtime (e.g. if you show some components based on the user input).
Happy to hear from anyone with more insight, I couldn’t find a reliable way to do this yet
Hey @jreke,
Thanks for pointing that out!
I dont think there can be any reliable solution to this right now for complex layouts, But the custom CSS feature is in development.
One more way that I can think of is to set the st.markdown dynamically as per the current layout.
SUB_CLASS_MAP = {
"main": ".st-bo",
"column": ".st-cs"
}
st.markdown(f"""
<style>
.stProgress {SUB_CLASS_MAP[the_key_goes_here]} {{
background-color: green;
}}
</style>
""", unsafe_allow_html=True)
Its definitely ugly but the your app will be able to adapt to the layout changes this way.
Hope it helps !
I think I found a solution now: The progress bar is nestled in a few divs within the div of class .stProgress
. So if you add CSS like below, it should reliably colorize only the progress bar itself, not the surrounding divs
st.markdown(
"""
<style>
.stProgress > div > div > div > div {
background-color: green;
}
</style>""",
unsafe_allow_html=True,
)
Let me know if that works!
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.
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.
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.
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.