A component that returns the active theme of the Streamlit app.
Slowing down. Last release over 2 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install st-themeStreamlit Theme
A component that returns the active theme of the Streamlit app.
Installation
pip install st-theme
Usage
The function immediately returns the active theme, when it is called. If the user manually changes the theme, after the web app is already running, it updates the returned value.
Parameters
adjust : bool, default=True
If set to True, which is the default, it makes a CSS adjustment and removes
a space that would otherwise be added to the page by calling the st_theme
function.
Streamlit components are meant to render something in the web app, and
Streamlit adds a space for them even when there is nothing to render. Since
st_theme does not render anything, and only communicates with the frontend
to fetch the active theme, it makes a CSS adjustment to remove this space.
In most cases, the CSS adjustment does not interfere with the rest of the web
app, however there could be some situations where this occurs. If this happens,
or it is desired to disable it, pass False to adjust and, when necessary,
make your own CSS adjustment with st.html.
key : str or int, optional
A string or integer to use as a unique key for the component. Multiple
st_themes may not share the same key. Defaults to None.
Returns
theme : dict of {str : str} or None
A dictionary with the style settings being used by the active theme of the
Streamlit app, or None, if for some reason it could not be fetched.
Notes
There is a known bug, that depends on the browser, where the theme is not returned immediately when the function is called. But it is returned normally when the user changes it.
This can be a problem in determining the initial theme of the web app. Because, by default, Streamlit uses the user's operating system setting (which might be unknown) to automatically apply the light or dark mode to the app, when it is first rendered.
To solve the issue, it is recommended to set a default theme configuration for the app, and use its value in case of returning .


