Is it possible to do conditional theming?

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:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.