Dear community! First of all thanks for providing Streamlit. It is such a great and wonderful tool and the app I develop would never be in its shape it is today without Streamlit (https://amfupapp.streamlit.app).
My system at the moment:
Python 3.12.4
Streamlit 1.39.0
I would like to enhance the user experience by introducing the dark app theme. I’m sticking with dark theme and SVG pictures at the moment. It is already there, but with my SVG graphics I come to the point that in dark mode the graphics get weird, below you find an example:
Inverting is no option for me as there are some graphics with a photo like style that would result in a negative of the picture. So I’m looking for a way to set the background of the SVG to white. I’m not experienced in CSS but my impression is that with CSS this could be done. So I would like to ask for your kind assistance. The preferred solution would be not to modify the SVG data itself but to inject some CSS code into the columns I use to display the SVG. Any hep would be great! No idea, if it is relevant for a solution, but in the text parts st.write also in combination the LaTex expression is used. Any help would be great, thank you in advance!
Thank you so much for giving support. This already looks very promising, I will give it a try! Please apologize my lack of knowledge regarding CSS Edwin (I really have to work on it) - so I would use a command like the following to implement it?
Is this what I have to provide before the SVG are shown with something like st.image(svg_pic, width=300), where svg_pic is the path to my pictures?
You asked about the SVG themself. They are located in a folder /svgs/pic1.svg, /svgs/pic2.svg, …, about 500 of them, different width and height. A typical example of simple SVG is the following:
I could imagine a batch job that inserts code in all the SVG, but I ask myself if this would be easier than the solution you proposed. A white background in Dark and White would do the job.
Almost, but not quite. CSS injections can be done using st.html(see st.html - Streamlit Docs). In your Python application, you’d write something like this:
Fantastic - works perfectly, you saved my day, thank you so much! Edwin, may I ask a further question that is strongly connected with the dark/light topic and CSS of this thread? If you say please open another topic, this would be absolutely fine for me (and would probably help to keep things separated). The second issue with dark app schemes is as follows:
I use the absolutely beautiful Custom Component streamlet-tree-select (New Component: streamlit-tree-select, a simple and elegant checkbox tree). So useful to display and select hierarchies! Here something similar happens in dark mode: text is nearly invisible. How could I fix this with CSS? The issue was raised by others in the discussion linked above, but unfortunately it was never fixed. Here an example:
That is a different issue and it is more difficult because custom components live inside an iframe, and, afaik, you cannot target the style within an iframe with CSS alone. This seems to be a known issue for that component, and it was fixed but they never updated the package in PyPI:
Thank you for your answer, Edwin. So, in GitHub there is a commit for request #8 by the owner of streamlit_tree_select (Schluca) that should fix the problem (contributed by BlueGob). Schluca was asked several times to update in PyPI but, as you confirmed, this never happened. This is really a pity as the component was praised by so many user and I’m sure that the demand on dark mode will raise for several reasons (OLED displays, ergonomic, …). Is it possible to fork the repo and publish it - maybe after renaming, referring to the source and respecting the corresponding license - in PyPI? In order to reduce maintenance efforts I could imagine that an easy “pip install streamlit_tree_select_whatever_new_name” would be a better approach compared to the solution (more a hack) that was proposed, namely replacing a special css-file in the python environment. What do you think?
Of course! If the component was ready to be used with the code as it stands right now in GitHub, you could even install it with pip directly by clonning the repo:
StreamlitAPIException: No such component directory: '/home/user/venv/lib/python3.12/site-packages/streamlit_tree_select/frontend/build'
Because this component was being made using React (I think) and it needs to be built before Streamlit can actually use it. So just republishing a fork of the repository won’t be enough. There is a bit more info in the “Create a bi-directional component” section at Intro to custom components - Streamlit Docs about this.
Edwin, this are mind blowing news! I did not expect that there is a PyPI package out there fixing the dark mode - so I didn’t even try. Instead I started reading the documentation for deployment on PyPI . Thank you for your search, I just released a new version of my app and voila.
Your support was extraordinary, Edwin. I am glad that people like you help the beginners and guide them into the right direction. This took the app to a new level in the last few days. I hope that it will help many users to pass the radio amateur exam.
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.