Hi guys,
Is there an easy way to amend Streamlitās default pink colourway via CSS like on the (amazing!) spacy-streamlit App?
Iāve tried various things yet no success thus far, so I thought I may just raise the question here!
Thanks,
Charly
Hi guys,
Is there an easy way to amend Streamlitās default pink colourway via CSS like on the (amazing!) spacy-streamlit App?
Iāve tried various things yet no success thus far, so I thought I may just raise the question here!
Thanks,
Charly
You can just rely on what spacy-streamlit do to override the theme. By looking at the source code, itās being done with:
def get_color_styles(color: str) -> str:
"""Compile some hacky CSS to override the theme color."""
# fmt: off
color_selectors = ["a", "a:hover", "*:not(textarea).st-ex:hover", ".st-en:hover"]
bg_selectors = [".st-da", "*:not(button).st-en:hover"]
border_selectors = [".st-ft", ".st-fs", ".st-fr", ".st-fq", ".st-ex:hover", ".st-en:hover"]
# fmt: on
css_root = "#root { --primary: %s }" % color
css_color = ", ".join(color_selectors) + "{ color: %s !important }" % color
css_bg = ", ".join(bg_selectors) + "{ background-color: %s !important }" % color
css_border = ", ".join(border_selectors) + "{ border-color: %s !important }" % color
other = ".decoration { background: %s !important }" % color
return f"<style>{css_root}{css_color}{css_bg}{css_border}{other}</style>"
st.write(get_color_styles("#09A3D5"), unsafe_allow_html=True)
Thanks Synode.
Yes, Iāve seen the above function in spacy-streamlit, yet couldnāt find a way to override the default pink colourā¦
Iāll keep digging
Charly
The above snippet doesnāt override it as you expect?
EDIT: Hmm, indeed, it doesnāt work very wellā¦
Hehe, I canāt make it work either
EDIT - @randyzwitch @andfanilo, is there anything obvious that weāre missing to override Streamlitās default colours?
Thanks,
Charly
I did something like this the other day and it worked:
st.markdown(
"""
<style>
.reportview-container .markdown-text-container {
font-family: monospace;
}
.sidebar .sidebar-content {
background-image: linear-gradient(#2e7bcf,#2e7bcf);
color: white;
}
.Widget>label {
color: white;
font-family: monospace;
}
[class^="st-b"] {
color: white;
font-family: monospace;
}
.st-bb {
background-color: transparent;
}
.st-at {
background-color: #0c0080;
}
footer {
font-family: monospace;
}
.reportview-container .main footer, .reportview-container .main footer a {
color: #0c0080;
}
header .decoration {
background-image: none;
}
</style>
""",
unsafe_allow_html=True,
)
So much of it is just fooling around with Chrome DevTools or whatever other browsers provide, trying to find the right CSS selectors
That works, fantastic hack Randy!
Iām wondering: is there a way to find what are the default CSS settings in Streamlit?
Charly
Wellā¦your two best bets are :
In the source code, most Styletron widget overrides are in widgetTheme.ts and more global CSS if you really are interested though.
Thanks Andfanilo, thatā useful, and I appreciate the detailed feedback!
Charly
Thank you. Looking for this
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.