The streamlit-themes
package provides a streamlined way to customize the visual appearance of Streamlit applications.
Note: This package accesses the internal config directly at st._config
, which is sort of a hack.
Use with caution. Also, updating the theme with streamlit-themes
updates the theme for the entire Streamlit app
(including all users), so it's not suitable for multi-user apps.
To install the streamlit-themes
package, simply use pip:
pip install streamlit-themes
If there is no custom theme provided in the .streamlit/config.toml file, then the getter functions will return None values upon startup, and the custom color widget will default to a black values. To avoid this, it's best to specify as custom theme in the .streamlit/config.toml file. For example:
[theme]
primaryColor="#3282B8"
backgroundColor="#f1f0e8"
secondaryBackgroundColor="#eee0c9"
textColor="#45474b"
font="sans serif"
Here's a basic example of how to use the streamlit-themes
package:
import streamlit_themes as st_themes
# Set a custom theme
st_themes.set_theme(
background_color='#FFFFFF',
primary_color='#1A73E8',
secondary_background_color='#F1F3F4',
text_color='#202124',
font='sans serif'
)
The following functions are available directly through streamlit-themes
:
import streamlit_themes as st_themes
-
get_theme
: Retrieves the current theme settings.current_theme = st_themes.get_theme()
-
set_theme
: Sets the theme with specified parameters (background color, primary color, secondary background color, text color, font).st_themes.set_theme( background_color='#FFFFFF', primary_color='#1A73E8', secondary_background_color='#F1F3F4', text_color='#202124', font='sans serif' )
-
get_preset_theme
: Retrieves the settings of a specified preset theme.preset_theme = st_themes.get_preset_theme('Beach')
-
set_preset_theme
: Applies a specified preset theme.st_themes.set_preset_theme('Beach')
-
get_all_preset_themes
: Retrieves all available preset themes.all_presets = st_themes.get_all_preset_themes()
-
custom_theme_widget
: Creates a Streamlit widget for customizing and applying themes.st_themes.custom_theme_widget()
-
preset_theme_widget
: Creates a Streamlit widget for selecting and applying preset themes.st_themes.preset_theme_widget()
-
Theme
: A class that represents a theme with background color, primary color, secondary background color, text color, and font attributes.theme = st_themes.Theme( background_color='#FFFFFF', primary_color='#1A73E8', secondary_background_color='#F1F3F4', text_color='#202124', font='sans serif' )
The streamlit-themes
package provides a set of preset keys that can be used to quickly apply predefined themes.
Beach
Pineapple
Peachy
Tropical
Mater
Gastly
Ocean
Abyssal
Green
Sandy
Sunset
Midnight
import streamlit_themes as st_themes
# Directly apply a preset theme
st_themes.set_preset_theme('Beach')