I started using the multi pages feature to create a streamlit app, so far its been nice. However I have encountered a sort of bug (Although I understand this is a expected behavior, because of my approach) . I am loading a custom css file to change the font of the app, I am doing this in every page .py file, now while it works, every time I switch between pages it takes a fraction of a second for the page to load the custom css and its quite noticeable and annoying.
I tried wrapping the code to load the css file with a st.cache decorator, but was greeted with a CachedStFunctionWarning.
This is the code to load the css file.
with open(file_name) as f:
Have you tried playing directly with Streamlit theming?
I don’t know how you wrote in the caching attempt, so if you could share how you structured it as a function that might shed some light. Also, have you tried the new st.experimental_memo? There can be some fiddly bits with caching, but if you cache the actual css to inject as a string to load on the page, I don’t think there should be a problem.
If you are really determined to get this done you could try injecting the custom stylesheet into the base HTML page of the installed Streamlit package. I would be hesitant to suggest a specific implementation but you can look here for inspiration. In one of my apps I adapted some of this code to be run at Docker image build time. Or just use that package’s API but try to understand what it does first and that it could break easily with changes in Streamlit.