Summary
When running streamlit with plotly graphs, my app is really slow. Here, I don’t mean the time it takes to create graphs, but just opening and closing the sidebar, say, gets stuck a lot and is very bumpy.
Also, when adding more than say 8 graphs or so to one page, I see no data in the graphs anymore and sometimes a sad smiley. I have seen this problem described in another post, but haven’t seen any solution yet…
Steps to reproduce
Code snippet:
import streamlit as st
import pandas as pd
import numpy as np
import plotly.express as px
if 'test_data_1' not in st.session_state:
st.session_state['test_data_1'] = pd.DataFrame(np.random.randn(5000, 1), columns=['Test_1'])
st.session_state['test_data_2'] = pd.DataFrame(np.random.randn(5000, 1), columns=['Test_2'])
st.session_state['test_data_3'] = pd.DataFrame(np.random.randn(5000, 1), columns=['Test_3'])
st.session_state['test_data_4'] = pd.DataFrame(np.random.randn(5000, 1), columns=['Test_4'])
cols = st.columns(3)
with cols[0]:
data_1 = pd.concat([st.session_state['test_data_1'],
st.session_state['test_data_2']],
axis=1)
fig = px.line(data_1,
x=data_1.index,
y=data_1.columns,
title='First')
st.plotly_chart(fig, use_container_width=True)
with cols[1]:
# prepare the dataframe to plot
data_2 = pd.concat([st.session_state['test_data_1'],
st.session_state['test_data_2'],
st.session_state['test_data_3']],
axis=1)
fig2 = px.line(data_2,
x=data_2.index,
y=data_2.columns, title='Second')
st.plotly_chart(fig2, use_container_width=True)
with cols[2]:
data_3 = pd.concat([st.session_state['test_data_1'],
st.session_state['test_data_2'],
st.session_state['test_data_3'],
st.session_state['test_data_4']],
axis=1)
fig2 = px.line(data_3,
x=data_3.index,
y=data_3.columns, title='Third')
st.plotly_chart(fig2, use_container_width=True)
Can others also observe the same speed issue with the above script? When copying down one graph to more columns, you can hopefully also replicate the vanishing data problem in the graphs.
Is there a way to make this faster and not crash when more than a certain number of plots are used?
Many thanks,
Chris
Debug info
- Streamlit version: 1.25.0
- Python version: 3.10.4
- Using PipEnv
- OS version: Windows
- Browser version: Chrome