Search code examples
pythonpandasstreamlit

streamlit displot takes too long


Based on following link: Streamlit displot

I have experimented on my own example on regression dataset:

import streamlit as st
import pandas as pd
import plotly.figure_factory as ff
data =pd.read_csv("https://raw.githubusercontent.com/krishnaik06/Multiple-Linear-Regression/master/50_Startups.csv")
print(data.head())
print(data.shape)
hist_data =[data['R&D Spend'].values,data['Administration'].values,data['Marketing Spend'].values,data['Profit'].values]
groups =["R&D spend","Administration","Marketing Spend","Profit"]
fig =ff.create_distplot(hist_data=hist_data,group_labels=groups,bin_size=[0.1,0.25,0.5,0.75])
st.plotly_chart(fig,use_container_width=True)

shape returns (50,5), so it is very small dataset, but when i am running code, it takes too long and returns following error :

enter image description here

could you please tell me how to fix it?


Solution

    1. According to the Plotly's create_distplot documentation,

      this function is deprecated, use instead plotly.express functions, [...]

    2. Using your current function, I still indeed have a similar problem, leading to my browser telling me "this page is slowing down Firefox". Making the size of the bins bigger alleviates the problem:

      fig = ff.create_distplot(hist_data=hist_data, group_labels=groups, bin_size=10000)
      

      It gives:

      enter image description here