Pretty self explanatory title but as it says, is it possible to adjust the text colour of a metric in streamlit based on the value, ie. if the value is very high the text is Red or if it is very low it is green?
Similar to styling a dataframe except obviously I want to display my data in st.metric() format as opposed to using a dataframe, but would still like the visual cues.
I can use markdown and css to change the font colour but as far as I am aware, it would not be possible to apply this to only one specific metric, and would likely change the colour of every other metric on the screen.
Define your number range of what constitutes High, Medium and Low (assuming you want these 3 categories)
Use the hacky way to modify the colour of your metric widget based on your number value. (I used another way which can be seen in the thread: Style Column Metrics like the Documentation. You can repurpose this code for your benefit)
I am not quite sure how this would work given that every single metric appears to have the same css class in the new version of streamlit, so I do not really see how you are able to apply different colours to different metrics?
(Apologies if I have misunderstood)
Does this mean the only possible way is to use the html string in your example?
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.