Compatibility issue with new version of plotly?
Hi guys, getting the following error with the explorer module:
AttributeError Traceback (most recent call last)
<ipython-input-9-38c8dacf5299> in <module>
----> 1 explorer.correlation_plot()
~/machine_learning/.env/lib/python3.7/site-packages/lens/explorer.py in correlation_plot(self, include, exclude)
311 """
312 fig = plot_correlation(self.summary, include, exclude)
--> 313 self.plot_renderer(fig)
314
315 def correlation(self, include=None, exclude=None):
~/machine_learning/.env/lib/python3.7/site-packages/lens/explorer.py in _render(fig, showlegend)
44 raise ValueError(message)
45 else:
---> 46 if not py.offline.__PLOTLY_OFFLINE_INITIALIZED:
47 py.init_notebook_mode()
48 return py.iplot(fig, **PLOTLY_KWS)
AttributeError: module 'plotly.offline.offline' has no attribute '__PLOTLY_OFFLINE_INITIALIZED'
I'm working in a python virtulaenv with the following setup
CPython 3.7.3
numpy 1.17.2
pandas 0.25.1
matplotlib 3.1.1
plotly 4.1.1
lens 0.4.5
system : Linux
release : 5.0.0-31-generic
machine : x86_64
interpreter: 64bit
I believe the issue to be come from recent updates in the plotly library with the integration of plotly_express js initilization in the python package.
Quickfix that worked was simply removing the if statement in line 46 of explorer.py
45 else:
46 if not py.offline.__PLOTLY_OFFLINE_INITIALIZED: # remove
47 py.init_notebook_mode() # unindent
48 return py.iplot(fig, **PLOTLY_KWS)
Might be worth a pull request?
Hi @maximemerabet - Thanks for the report and the complete diagnosis. Definitely worthy of a PR, go ahead if you want to do it, otherwise I'll do it in a couple of days.
Happy to do it @zblz , would you like me to update the version requirement in setup.py as well?
This link quotes
Prior to version 4, this library could operate in either an "online" or "offline" mode. The documentation tended to emphasize the online mode, where graphs get published to the Chart Studio web service. In version 4, all "online" functionality was removed from the plotly package and is now available as the separate, optional, chart-studio package (See below). plotly.py version 4 is "offline" only, and does not include any functionality for uploading figures or data to cloud services.
More details here
Yeah, bumping the version required to a minimum of 4.0 would make sense. Eventually we could also use the renderers framework, which is much nicer than the plotly.offline methods, but since they have kept them for backwards compatibility it's not critical to do so.