I was looking for an update on how to display Javascript content in a notebook, opened with Jupyter Lab, so I though here was the best place to get one…
The extension is always active (i.e. no need to run npm i @jupyterlab/javascript-extension as stated on the npm repository) ?
If so maybe I’d recommend to confirm that no install is required on the extension’s README. Also maybe the current example,
Javascript('console.log("hello world");')
could be replaced with
Javascript('alert("hello world");')
which effect is simpler to spot, at least for non-JS experts?
Last but not least, what is the recommended way to load require in Jupyter Lab? I am aware of a code snippet that looks like this
from IPython.display import HTML, display
from time import sleep
display(HTML("""
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.10/require.min.js"></script>
"""))
sleep(0.1)
(thanks @fcollonval !) but now I am looking for a more robust approach (i.e. without sleep)
Edit: this is a forward looking statement made in 2021: no guarantee it will happen, nor that it will happen exactly as described in the linked, but looks exciting!
As for the sleep - I think it is there just to give the frontend a bit of breathing room to load the script before processing anything after that may use the require library. If your display call is the only thing in the cell, I think you probably don’t need the sleep.
Also I should report on the latest research that I did for the itables package:
ES imports work well in all the notebooks environment I have tested (Jupyter Notebook, NB convert, Lab, Jupyter Book, VS Code, PyCharm, Google Colab), so I’d recommend to use ES imports when possible.
However for Javascript code that uses require we need to manually import require.js in some cases (with the code snippet above), as require.js is pre-imported only in Jupyter Notebook, NB convert and Jupyter Book.
First I must say that I know very little about JS - All I know is that I was advised to use ES modules as they sound like the modern way to load JS libraries.
Is the issue of SRI integrity specific to https://esm.sh?
Also in the case of https://datatables.net/ I could not find an ES version supported by the author, and that is the primary reason for using https://esm.sh. But certainly when another version with native support for ES imports is made available (maybe on another CDN?) I’ll take that one.
First I must say that I know very little about JS - All I know is that I was advised to use ES modules as they sound like the modern way to load JS libraries.
Is the issue of SRI integrity specific to https://esm.sh?
Yes (and it might change one day).
But certainly when another version with native support for ES imports is made available (maybe on another CDN?) I’ll take that one