I am trying to write a library that will embed some JavaScript into a Jupyter notebook. The code works fine using %%javascript
magic, but I want to embed the loading of the JavaScript into a library call. I found this SO post: Jupyter Notebook, Python: How to call a magic from within a function? but it only partially works.
The following code correctly runs the JavaScript alert:
from IPython.core.magics.display import Javascript
Javascript('alert("hello world")')
The following, however, does not work (nothing happens; no console errors):
from IPython.core.magics.display import Javascript
def foo():
Javascript('alert("hello world")')
foo()
How do I embed a working call to Javascript within a function?