Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save Jupyter Notebook with Plotly Express widgets displaying

I have a Jupyter notebook (python) where I used plotly express to plot in the notebook for analysis purposes. I want to share this notebook with non-coders, and have the interactive visuals be available still - but it does not seem to work.

I tried following recommendations made here but even after saving widgets state and using nbconvert, when I open the new HTML file, the visuals are not available.

A sample line of plotting can be seen below:

import plotly_express as px
fig = px.scatter(
    df, 
    x='size', 
    y='size_y', 
    color='clients',
    hover_data=['id'], 
    marginal_y="histogram", 
    marginal_x="histogram"
)
fig.show()
like image 673
guyts Avatar asked Sep 05 '25 03:09

guyts


2 Answers

After running plotly.offline.init_notebook_mode() in a cell, you can export the notebook with full interactivity via the file menu: File --> Export Notebook as... --> Export Notebook to HTML.

like image 141
joelostblom Avatar answered Sep 07 '25 20:09

joelostblom


I was having similar issues but with JupyterLab. Followed the instructions here: https://plot.ly/python/renderers/ .

import plotly.io as pio
pio.renderers.keys()

I had to add the following snippet to my script:

import plotly.io as pio
pio.renderers.default = 'jupyterlab'

Exporting as HTML after that worked for me. You can read "Overriding the default renderer".

I suppose you would need

pio.renderers.default = 'notebook' 
like image 38
hamiq Avatar answered Sep 07 '25 20:09

hamiq