I have a streamlit app that displays a pandas styler object created from a dataframe.
It is not a particularly huge dataframe, about 300 rows, and the styler just loops over columns and highlights them good/great/improve based on their values. To generate the styler takes no time at all, but once it gets displayed on screen, the google chrome renderer starts eating massive amounts of CPU to the point where the dashboard becomes unusable exceeding 100% cpu usage just trying to scroll down the dataframe. I don’t really understand this cos I would have thought at this point, no more code is being run, and it implies it is literally struggling to just render this dataframe?
When I switch back to a dataframe instead of a styler, the performance immediately improves dramatically.
Has anyone come across this or have any ideas what might be causing this?
Here is an example of one of the styling functions.
def highlight_overall(numbers):
highlight_list = []
for i in numbers:
if i >= 80:
highlight_list.append("background-color: #99DEBB")
elif i < 70:
highlight_list.append("background-color: #ffbb9e")
else:
highlight_list.append("background-color: #fdff9e")
return highlight_list
Here is a graph of my CPU usage when trying to scroll on the styler