Hello everyone. I am currenlty working on an app, with different layouts according to command line arguments which define the “mode”, but I wasn’t able to change the theme for each mode. I tried with css, but I didn’t know how to change the primary color attribute, so I tried modifying the config.toml file when executing the app. This is an example of what I am trying:
import streamlit as st
import sys
mode = sys.argv[1]
if mode == "mode_1":
theming = """
[theme]
base="light"
primaryColor="blue"
"""
else:
theming = """
[theme]
base="light"
primaryColor="red"
"""
with open(".streamlit/config.toml", "w") as file:
file.write(theming)
if mode == 'mode_1':
st.title('Mode 1')
do_something(mode)
else:
st.title('Mode 2')
do_something(mode)
However, this won’t work, not even running the file two times, or modifying the config file previously. Even I tried modifying the config file located on my user .streamlit folder, but the app only uses what was defined in a previous run, not what the config file says.
I am using Streamlit version 1.24.0 with Python version 3.8.17
Unfortunately, updates made to configuration while the app is running requires a reboot to take effect. You would need to hack around it with custom CSS and maybe JavaScript using Streamlit components to get some equivalent of conditional theming. There appears to be a similar request on GitHub if you would like to upvote it so the devs can track interest:
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
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.
Performance cookies
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.
Functional cookies
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.
Targeting cookies
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.