I would think you need to wrap the js_code part in IPython,display’s Javascript, like here and here and not wrap it in like you have; however, I couldn’t find a more complex example involving a function to point out. Here has a function defined there but it is using an ipywidget library.
Related topics
| Topic | Replies | Views | Activity | |
|---|---|---|---|---|
| Different behavior between notebook and lab with ipython.display.html() | 10 | 2788 | August 29, 2019 | |
| Embedding IpyWidgets outside Ipython notebook | 1 | 3958 | March 21, 2021 | |
| JLab or IPython issue: inconsistency in IPython.display behavior between JLab and classic notebook or google colab? | 2 | 1270 | July 2, 2022 | |
| How to execute cell in JupyterLab (javascript:Jupyter.notebook.execute_cells not working) | 4 | 2223 | December 20, 2023 | |
| IPython not defined from Javascript | 2 | 1411 | September 2, 2024 |