Look at the sidecar package for how this works: https://github.com/jupyter-widgets/jupyterlab-sidecar