repr icon indicating copy to clipboard operation
repr copied to clipboard

Notebook Display Outputs Unrenderable in Conversion

Open MSeal opened this issue 5 years ago • 4 comments

A replication from github.com/ropensci/plotly/issues/1763 where the issue could not be addressed directly.

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.

More details from that thread led to posting in this project, but essentially the html outputs in the cell aren't renderable without javascript extensions present, which on a plain html file don't exist.

Furthermore, looking through the file it seems like every script associated has a the png embeded into the html, causing the rendering to be duplicated on every media type including text. You likely want to only render the PNG on the image output and leave the other with the raw data to reproduce to PNG. This causes a multi-kilobyte display output to take megabytes of space.

I'm cross posting this with https://github.com/ramnathv/htmlwidgets as I'm not familiar enough the packages here to know where changes would need to be made.

MSeal avatar May 26 '20 19:05 MSeal

https://github.com/ramnathv/htmlwidgets/issues/371

MSeal avatar May 26 '20 19:05 MSeal

The repr_*.htmlwidget code is here: https://github.com/IRkernel/repr/blob/master/R/repr_htmlwidget.r

The way it works is that it creates standalone single page HTML code (e.g. embedding all scripts as data:urls) and publishes it with Jupyter’s isolate: true (i.e. it gets rendered in an iframe by Jupyterlab). This raises two questions:

  1. @jcheng5 It would be nice to know if by now there was an upstream way to create standalone single-page HTML code using a function in htmlwidget instead of my hand-rolled solution. <script src="data:super-long-data-url"></script> is handled badly by some browsers.
  2. @MSeal How does nbconvert treat "isolate": true outputs? Does it properly do it at all?

For the special case of plotly: Since there’s a special plotly rendering plugin for Jupyter lab, that’s why things work fine in the front-end. Plotly plots don’t go through the generic htmlwidget rendering function but a special hand-crafted renderer.

flying-sheep avatar May 27 '20 12:05 flying-sheep

@MSeal How does nbconvert treat "isolate": true outputs? Does it properly do it at all?

Hmm no it doesn't. I found the issue you made for that https://github.com/jupyter/nbconvert/issues/129 which predated my involvement in nbconvert. If we need this to enable what's needed I could look into what's needed to add that into the 6.0 release that's wrapping up soonish.

For the special case of plotly: Since there’s a special plotly rendering plugin for Jupyter lab, that’s why things work fine in the front-end.

Yeah though that usually makes it fairly unfriendly for other Jupyter front-ends and for any headless executions as it's lab specific, so it helps if there's a fallback for other interfaces to have a functional solution.

MSeal avatar May 28 '20 16:05 MSeal

Yeah, so I guess there’s nothing repr can do here. I’ll leave this open in case we think of something to do more elegantly here.

flying-sheep avatar May 28 '20 17:05 flying-sheep