<@U01458NR7TR> The problem is that in Plotly.kt I ...
# datascience
a
@Peter The problem is that in Plotly.kt I can't properly load the JS bundle before the execution because notebook isolates different cells. How do you manage to do that in your example? Isolated pages + js from cdn?
p
My UI components (I mostly wrap eCharts) can render both a full HTML page (asHTMLPage) or just a HTML snippet (asHTML). The full page render contains a header with the link to the required javascript libraries and css files. Perhaps not very memory efficient, but very isolated :) Then based on the mode I'm running in I call one or the other when rendering the UI components:
Copy code
override fun render(notebook: Notebook): DisplayResult {
   return when (mode) {
       Mode.LAB -> HTML(asHTML())
       Mode.NOTEBOOK -> HTML(asHTMLPage(), true)
   }
}
a
Ok, good idea, it will work only with cdn-based bundles, not local ones, but it is still a good workaround, thanks.
p
To be honest like the Lab environment much more, since more flexible and faster. But still a lot of classic notebooks out there,
a
For example DataLore 🙂
p
Actually I have a switch to include the resources rather than to use a CDN, this works also,
a
Yes, the same here, but the problem is that Plotly is about 2 MB, if I will embed it in each cell...
It would help a lot if one could share JS bundles between cells in a classic notebook, but I just did not found any possible way in the documentation
p
I also could not get this to work. Long ago did some work on Google iframed portal (at that time Googles Social Media vision 😉, and it is possible to exchange info between iframe and its parent. But very tricky.
For example to post a message to the parent
Copy code
window.top.postMessage('Do Something', '*')
a
There is an API in jupyter kernel that allows to load JS bundles, I hope that in furure there will be also an API that allows to access them from js.
p
To be honest, I think isolation through iframes is somewhat of an outdated concept. So my hope is that JupyterLab quickly gets more traction (also much better at using available screen estate).
a
@Peter thanks a lot for your hint, I've implemented it in plotly and now it works fine for classic notebooks as well (with CDN loading only of course).
👍 1
p
Pro tip 😉 : you can now also offer a save-to-file option for a chart since that same HTML page you generate, can also easily be saved to disk and people can share/access that as a standalone HTML file.
a
Export to file worked even before that. And there are no problems with embedding JS there. I had full page render before. What I had not is the manual switch to notebook mode.
p
I see. What I would really like that the Jupyter Integration API just tells me if I'm in a Classic or Lab environment. Then this switch is not a end-user responsibility anymore.