Streamlit does not change theme with config.toml file

Summary

I have created a config.toml file in my streamlit project. Whenever I run my python file, the theme from the toml file doesn’t change in my app. I’m using pycharm as an IDE.

Steps to reproduce

My pycharm file list looks like this. Did I create the config.toml file correctly?
Screenshot 2022-10-26 at 14.22.16
Screenshot 2022-10-26 at 14.20.53
My config.toml file look like this.

How can I make sure that my python app uses the toml file?

Hi @jbaekelm, welcome to the community :wave:

From your screenshot it looks like you’ve misspelled the filename as congif.toml, instead of config.toml

Happy Streamlit-ing! :balloon:

Hi @snehankekre

Thank you for the quick reply. I have changed that. Still no improvement. I have looked with streamlit config show.

What can I do next?

Did you explicitely set the theme to “Custom theme” in the hamburger menu? Sometimes it doesn’t work by simply placing the .toml file in the .streamlit folder.
I find this very confusing as well. Would be better if the app itself could enforce to use the custom theme if available through st.set_page_config.

3 Likes

Where are you running streamlit config show from? If you are running it from inside the app folder, then it won’t pick up on the .streamlit folder, and so will ignore the config.toml file. If you are running it from the top level folder it should recognize and use the config file.

Also, what version of streamlit are you using?

Hello, I have the same issue.

I created a config.toml file in a .streamlit folder, itself in my app/root folder. I changed the base theme to “dark” but it does not apply.

1 Like

Hi Pat! Your file shows that the base = "dark" line is commented out. Try removing the # prefix on that line. :slightly_smiling_face:

1 Like

oh Gee!.. beginner’s mistake :upside_down_face:… Thanks a lot @mathcatsand. Next time, I will double-check before posting something. :confused:

I have tried the following and did not work

Also tried the following and nothing:

Help!

Hi @christian_heins,

Can you check that your .streamlit (which contains config.toml) folder is in the same directory as the Streamlit app.py.

Please consider the following directory structure:

Root
├─ .streamlit
│  └─ config.toml
├─ README.md
├─ packages.txt
├─ requirements.txt
└─ streamlit_app.py

Best regards,
Chanin

Hi chanin!

Thank you for the quick response, as you can see from the screen shots I am having the suggested structure already.

Root
├─ .streamlit
│ └─ config.toml
├─ README.md
├─ requirements.txt
└─ ambelin.py

Screenshot 2023-04-16 at 15.27.44

Hi,

The directory structure looks right and the content of config.toml looks good. Can you check to see if the quotation marks in the config.toml is not the curly quotation marks which may come from copy-pasting contents from web browsers.

Or also try downloading this config.toml from the Streamlit app-starter-kit.

Best regards,
Chanin

Hi chanin,

I tried replacing the config.toml in my app with the one you provided, still no success.

My app config.toml file:
Screenshot 2023-04-17 at 08.56.17

Nevertheless I deployed a new app using the app starter kit template, and it works perfectly. I changed the background color to bright yellow to check the result.

Template config.toml file:

I am guessing this might be then a conflict in my code? I am experiencing a similar problem here same with the page names, when using show pages. The names change only for a while, and after a while the page names return to the file names.

#Pages
page_real_estate_general_dashboard = "ambelin.py"
page_maps = "pages/maps.py"

show_pages(
    [
        Page(page_real_estate_general_dashboard, 'General Dashboard', "🏠"),
        Page(page_maps, 'Maps', "🗺️"),
    ]
)

UPDATE!

I decided to change the main app name from “ambelin.py” which is my project name to “streamlit_app.py” and all works like a charm (I had to delete the app and redeploy it, since the main file name changed), the show pages problem thing still persist, my page name are not being picked correctly.

Somewhere inside the config.toml methodolgy - process the app looks for this specific name “streamlit_app.py” and no other file name?

1 Like

Not the case, fortunately. As mentioned in Configuration:

If changes to .streamlit/config.toml are made while the app is running, the server needs to be restarted for changes to be reflected in the app.

Instead of renaming your main script and redeploying the app, rebooting the app (on Community Cloud) or restarting the app would have also worked.

1 Like

I have other apps where the main app name is different to “streamlit_app.py” and the theme is still not being picked up. This change here worked for me. I will test changing the file name to “streamlit_app.py” In the other apps as well.

NOTE.

I tried rebooting the app, but since the main file name changed from “myproject.py” to “streamlit_app.py”. I had to delete the app and redeploy as new to set the new main file path to “streamlit_app.py”.

For me the the issue was already when I ran locally. It had worked perfectly with my config file, until yesterday when it just didn’t.

What I had done a few days ago was show off the “theme function” to a colleague. I had then manually pressed the hamburger menu (on localhost:8501) → Settings and chosen Light theme instead of my usual Custom Theme. Apparently, I just realized, this change persisted through multiple reruns, reloads, computer turned on and off and what not. I had to go back to my hamburger menu and choose Custom Theme again, and now my own theme is working perfectly.

Since this change persisted across so many reruns, there has to be some link or variable somewhere that is kept for future use (@streamlit-crew do explain :slight_smile:). That could also explain why changing names of the app makes it work again, as some of you did.
I haven’t tried deploying it with my accidental manual light theme settings, so I don’t know if that kept variable would follow to the cloud or not, but it might.
Hope this helps someone!

@Mianen

I understand, somewhere in the api the streamlit_app.py name get’s picked up,

the difference between these 2 apps, is the main.py file, on the first one is called

1.wggesucht.py
https://christianheins-wggesucht-wggesucht-2lmx07.streamlit.app

  1. streamlit_app.py
    https://christianheins-wggesucht-test-streamlit-app-u8oehb.streamlit.app

On the second one, the blue theme get’s picked up and the initial state of the app is “light”, not “dark mode”.

@StreamlitTeam

1 Like

This has also solved it for me. Thanks you!!

For me, the problem was that windows did not recognise my file as being a .toml file. Copying the credentioals.toml file from ~./streamlit and changing its name and contents to be a config.toml file fixed the issue.