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