I created a lab extension using the mimerender-cookiecutter <https://github.com/jupyterlab/mimerender-cookiecutter>, but cannot figure out how to create a Comm object to send custom messages between the frontend and a notebook kernel. When I try to open a comm instance in the kernel-side code, the web console displays an error message that my comm object is "not found in registry".
1. Based on the Comms Doc Page <http://jupyter-notebook.readthedocs.io/en/stable/comms.html>, I am calling a "register_target" method in the load_ipython_extension() function in nb_extension.js: export function load_ipython_extension() { console.log('load_ipython_extension'); define( ['nbextensions/jupyterlab_foo/index', 'base/js/namespace'], (Extension, Jupyter) => { const { notebook } = Jupyter; Extension.register_renderer(notebook); Extension.render_cells(notebook); // New code: // Register comm object per http://jupyter-notebook.readthedocs.io/en/stable/comms.html Jupyter.notebook.kernel.comm_manager.register_target('my_comm_target', function(comm, msg) { console.log('registering comm target'); comm.on_msg(function(msg){console.log('on_msg()')}); comm.on_close(function(msg){console.log('on_close()')}); //comm.send({'foo': 0}); }); } ); } Is this the right place to register comm objects? It's the only js code that has access to the Jupyter object, as far as I can tell. Side note: the rest of the extension works, even though I don't see either of the console.log messages I added to my load_ipython_extension() call. Is this code being executed outside of the browser somehow? 2. In my kernel (python) code, I am initializing a Comm object per that same Comms doc: from ipykernel.comm import Comm my_comm = Comm(target_name='my_comm_target', data={'foo': 1}) And when the Comm object is initialized, an error message "Object not found in registry" is written to the javascript console. Can anyone comment on whether this code should or should not work? Is there any way to get visibility into the load_ipython_extension function? I would sure appreciate whatever help anyone can provide, as I am completely stumped. -- You received this message because you are subscribed to the Google Groups "Project Jupyter" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/daaa0d16-8a82-4f90-b866-bc6e37b14862%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
