7

My jupyter notebooks that have plotly plots do not retain the plots between sessions.

This is running on a Singularity container based on the official jupyter/datascience-notebook docker image with plotly pip installed on top.

I am using the new renderer framework with the notebook renderer. My notebooks are trusted. My plots show up during the session without issues. They persist across refreshes and reloads of the same notebook, even if I restart the kernel. They disappear either when I restart the jupyter server or sometimes when I reboot the client machine and come back with a new browser session. The output cells persist with the correct dimensions, but they are blank. I can see that a whole bunch of js is embedded in the notebook but it does not render in the browser. At this point, even if I nbconvert to html, they still do not show up. Tried with Chromium and Firefox.

import plotly.graph_objects as go
import plotly.io as pio
import plotly.express as px
pio.renderers.default='notebook'

then later I plot a bunch of things like:

go.Figure(go.Scattergl(x = var1, y= var2, mode='markers', marker_size=1))

and

go.Figure(go.Histogram2dContour(x = var1, y= var2))

My understanding is that I am set up to retain these figures in offline (non-running) notebooks; the js generated for the plots and the entirety of plotly.js library appears to be embedded in each notebook adding up to 10s of MBs, but they are not rendered. Due to this issue I end up having to re-run (sometimes expensive) notebooks when all I need is to take a look at a previous plot.

As a recent matplotlib/seaborn convert I absolutely love the interactivity but this is quickly becoming a showstopper at this point. I feel like I'm missing something. Any advice is appreciated.

1 Answers1

1

For me, the following solution worked :

  • in the environment you're using : install orca : conda install -c plotly plotly-orca
  • at the beginning of your notebook : override default renderer as 'notebook' :
import plotly.io as pio
pio.renderers.default='notebook'

plotly graphs were persistent between sessions (ie : after restart of kernels) with these modifications.

Dharman
  • 30,962
  • 25
  • 85
  • 135