What is the 2022 way to display Javascript in a Python notebook in Jupyter Lab?

Hello everyone!

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…

Is it correct that

  1. Since 2019, the @jupyterlab/javascript-extension is shipped with Jupyter Lab
  2. 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)

Thanks!

1 Like

2022 is here: Improved `%%javascript` cell magic. · Issue #13376 · ipython/ipython · GitHub

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!

3 Likes