Plotly R not rendered in html output
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
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.
Is this issue related to #129?
No I think that's a separate concern with regards to assumptions R packages are generating outputs and tooling not accounting for that.
I reposted the issue in the underlying R packages to hopefully get the right maintainers to fix their outputs.
I am facing the same issue now. Has there been any progress since 2020? Any workaround available? Thanks.