How to render chart faster

Hi!
Using more and more streamlit, I start to get larger apps.
I tend to use plotly for my charts, and plotly can be a bit slow to display large dataframe.
I tried to cache part of it, without success.
Did anyone successfully cached something in the plotly fig to plotly_chart ?

Another way would be to disconnect the heavy chart from some widgets event, if they have no logical link, but I guess this is not possible yet (did not see it in the documentation).

Hi Phil,
I’m not sure I got your point but have you tried caching all the figures objects themselves in a dict or list:

@st.cache(hash_funcs={dict: lambda _: None}) # hash_funcs because dict can't be hashed
def get_dic_of_fig():
    dico_of_fig = {}
    for param in list_of_params: 
        plotly_fig = plot_plotly_fig(param)
        dico_of_fig [param] = plotly_fig 
    return dico_of_fig 

dico_of_fig = get_dic_of_fig() # this dic is cached

and later

st.plotly_chart(dico[param_chosen])
2 Likes

Excellent, thanks Vincent!
Saved 5s of loading for the user :slight_smile:
I plot line charts with 4 or 5 curves of 20k rows. Not that large, but plotly is not that fast (but bring good interaction).

1 Like