nbconvert icon indicating copy to clipboard operation
nbconvert copied to clipboard

Plotly R not rendered in html output

Open LustigePerson opened this issue 5 years ago • 5 comments

Issue

When using R Plotly in a Jupyter Notebook, the interactive widgets will not appear in the output when using nbconvert to transform it to html. Console in the browser says: Uncaught ReferenceError: Plotly is not defined.

I am not quite sure if this issue is caused by plotly, jupyterlab, or nbconvert, but as it is working in the notebook I'd thought it might belong here.

Reproduce

You can use the jupyter-stacks R image and install plotly to test:

docker run -it -p 8888:8888 jupyter/r-notebook bash


conda install -y r-plotly

export NODE_OPTIONS=--max-old-space-size=4096
jupyter labextension install @jupyter-widgets/jupyterlab-manager --no-build
jupyter labextension install jupyterlab-plotly --no-build
jupyter labextension install plotlywidget --no-build
jupyter lab build
unset NODE_OPTIONS

jupyter lab --NotebookApp.token=''

Without the labextensions, the widgets are rendered within the notebook but they don't look right (the height of the output field is to low).

When you access the notebook (localhost:8888) just try a standard plot, e.g. :

library(plotly)
fig <- plot_ly(y = ~rnorm(50), type = "box")
fig <- fig %>% add_trace(y = ~rnorm(50, 1))

fig

This should render fine within the notebook, but saving as html (via jupyter lab interface or via nbconvert from the terminal) is not working, i.e. the output is missing.

For Python this is working fine with the jupyter lab extensions.

Versions

I use the docker image provided by jupyter, see above. Nbconvert version: 5.6.1

LustigePerson avatar May 11 '20 09:05 LustigePerson

Thanks for the detailed error report. So I dug into the rendering issue and what's happening is that the widget is outputting raw html with script references to code that only exist when the extensions are installed. There's also a png output but nbconvert is preferring the html to be used in an html format. I'm not exactly sure what the best approach should be in this case. @jasongrout might have thoughts on what we maybe should recommend the widget do or for us to detect something to hint that the conversion should use png instead.

MSeal avatar May 12 '20 18:05 MSeal

Is this issue related to #129?

LustigePerson avatar May 26 '20 07:05 LustigePerson

No I think that's a separate concern with regards to assumptions R packages are generating outputs and tooling not accounting for that.

MSeal avatar May 26 '20 18:05 MSeal

I reposted the issue in the underlying R packages to hopefully get the right maintainers to fix their outputs.

MSeal avatar May 26 '20 19:05 MSeal

I am facing the same issue now. Has there been any progress since 2020? Any workaround available? Thanks.

soungalo avatar Aug 14 '23 08:08 soungalo