Has anyone used
st.metric in a dataframe before?
I want to add a column in a dataframe that shows something like a percentage increase/decrease based on some of the other columns values, and I was wondering if I can use
st.metric for that in every single cell of that column?
st.metric isn’t a data type that can be saved into a dataframe; it’s a function that “does a thing” which is to render something on the front end and return its value to the back end. If you want to display something that looks like what
st.metric produces, you’d have to manually do something to achieve that.
There are some styling effects in pandas you can use (like bar plot or manually styling red and green arrows), but styler support is limited in Streamlit without using the
.to_html() method and doing a static rendering of the dataframe. Since font color and background color should be supported for
st.dataframe, you can probably work something out with maps to convert a column to strings, appropriately append arrows, and color each cell’s font as desired.
Aggrid is also available but I would have to defer to others about what’s available and how to do it.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.