https://kotlinlang.org logo
Title
a

altavir

05/30/2021, 12:53 PM
@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

Peter

05/30/2021, 1:04 PM
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:
override fun render(notebook: Notebook): DisplayResult {
   return when (mode) {
       Mode.LAB -> HTML(asHTML())
       Mode.NOTEBOOK -> HTML(asHTMLPage(), true)
   }
}
a

altavir

05/30/2021, 1:05 PM
Ok, good idea, it will work only with cdn-based bundles, not local ones, but it is still a good workaround, thanks.
p

Peter

05/30/2021, 1:05 PM
To be honest like the Lab environment much more, since more flexible and faster. But still a lot of classic notebooks out there,
a

altavir

05/30/2021, 1:06 PM
For example DataLore 🙂
p

Peter

05/30/2021, 1:06 PM
Actually I have a switch to include the resources rather than to use a CDN, this works also,
a

altavir

05/30/2021, 1:07 PM
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

Peter

05/30/2021, 1:12 PM
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
window.top.postMessage('Do Something', '*')
a

altavir

05/30/2021, 1:20 PM
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

Peter

05/30/2021, 1:25 PM
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

altavir

05/30/2021, 2:27 PM
@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

Peter

05/30/2021, 2:48 PM
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

altavir

05/30/2021, 2:49 PM
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

Peter

05/30/2021, 2:53 PM
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.