Did some investigation on Kotlin kernels in Jupyte...
# datascience
Did some investigation on Kotlin kernels in Jupyter Classic vs Lab. Right now Kotlin packages for notebooks differentiate between on how they render HTML output between the two. In a Classic environment they use isolation (resulting in an iframe) and Lab they use non-isolated (resulting in insert of plain HTML snippet). This approach works fine, but means you have to be able to differentiate between the two which is hard to due reliable. Letting the user decide is also not ideal. This differentiation is however not required. Classic & Lab both support non-isolated mode. The real problem packages encounter with Classic notebooks is that Jupyter Classic is including requirejs library that changes how third-party JavaScript libraries behave when they are loaded. If they detect require/define functions, they will not load themselves in global scope but instead use the require API. Quick workaround: ============== Disable this detecting behaviour in the JavaScript library you are loading so they don’t detect require framework anymore. They will behave now the same as Jupyter Lab, basically load themselves in the global namespace and work fine in non-isolated mode. In my case with ECharts JavaScript library, the following change was all that was required to disable detection: Replace:
"function"==typeof define
"function"==typeof define_none_existing
Of course if you load the script from a CDN, changing the code is not possible. But if you load it from resources directory (classPath option in your JupyterIntegration implementation) it is an easy change for most JavaScript libraries. Future better workaround: ===================== The code that Kotlin kernel generates to embed external JavaScript libraries could take care of this behaviour. It could detect requirejs presence and change it loading behavior. But this requires more investigation.
What if we are using our own Kotlin-JS bundles instead. Is it enough to avoid using requireJS for bundling?
As long as your JavaScript doesn’t use require/define functions to wrap itself during loading, it should be fine. Problem is that many of the popular JavaScript libraries all check for requirejs the same way. For example I saw exactly same code in Plotly as ECharts.
Yeah. I think that the more universal solution would be to work with Jupyter itself to allow secure dynamic loading shared JS code.