Cufflinks in Streamlit

I am trying to plot using cufflinks as follows:


but I get the following error:

module 'plotly.offline' has no attribute '__PLOTLY_OFFLINE_INITIALIZED'

I have tried to enable offline plotting by:


But the problem still there. I am using Plotly 4.5.4 and cufflinks 0.5

Can our amazing Streamlit support plotting using cufflinks?

Hello @Abusnina , welcome to the forums :slight_smile: !

This is odd, if I recall correctly but I’m no plotly expert, just read it somewhere one day… starting from plotly 4 there should not be a need to define plotly offline :confused: so I don’t understand how this error can appear if you are effectively on plotly 4.5.4.

On my side, with Streamlit 0.57.0 Plotly 4.5.4 and cufflinks 0.5 and 0.17.3 the following works :

import cufflinks as cf
import pandas as pd
import numpy as np
import streamlit as st

df = pd.DataFrame(np.random.randn(1000, 2), columns=['A', 'B']).cumsum()
fig = df.iplot(asFigure=True, xTitle="The X Axis",
                    yTitle="The Y Axis", title="The Figure Title")


Oh wait, actually you need to pass the asFigure=True inside iplot to actually return a plotly object that st.plotly_chart can interpret ! If I remove it from my code it doesn’t work like you get.

Can’t find the corresponding docs except for here :

By passing the asFigure=True argument to .iplot() , Cufflinks works similarly to Plotly Express, by returning customizable go.Figure objects which are compatible with Dash’s dcc.Graph component. Cufflinks also adds a .figure() method which has the same signature as .iplot() except that it has asFigure=True set as the default.

Does it work by passing the argument ?