Yes, make a notebook nbextension, which is the preferred way to get javascript on the page:
https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Distributing%20Jupyter%20Extensions%20as%20Python%20Packages.html On Wed, Nov 22, 2017 at 7:12 PM John <[email protected]> wrote: > OK I figured out what my problem was. In my kernel python code I was > setting up the comm channel with these two lines of code. > > display(Javascript("""require(["nbextensions/vpython_libraries/glowcomm"], > function(){console.log("GLOWCOMM LOADED");})""")) > comm = Comm(target_name='my_comm_target') > > The first line would run javascript code which in turn registered the > target on the javascript front end. The second line would connect to the > target from the python side. If I put a time delay between these two > commands then the problem goes away because the javascript code has time to > execute to register the target to which I am trying to connect the Comm > channel to. > > Is there an alternative approach to ensure that the javascript file I > require is loaded when the notebook is opened? > > John > > > > On Wednesday, November 22, 2017 at 4:10:37 PM UTC-8, Jason Grout wrote: > >> Can you turn on the browser debugger and have it pause on errors, and see >> what the lines of code are that are giving the problem (what are the lines >> of code, not just the line numbers)? I would probably debug this by also >> putting a breakpoint at the registration function and making sure that was >> working (i.e., step through the code and make sure that an entry was stored >> in the kernel's comm registry). I would also step through the code where >> the error happened and inspect the registry. >> >> For reference, here is where we are registering a target in >> widgetsnbextension: >> https://github.com/jupyter-widgets/ipywidgets/blob/bbfc39ec0f9e49f730d25bc5347d39e18992a54b/widgetsnbextension/src/manager.js#L71 >> >> >> Thanks, >> >> Jason >> >> >> On Wed, Nov 22, 2017 at 2:30 PM John <[email protected]> wrote: >> > Hi >>> >>> I tried opening a Comm from the kernel as described in >>> >>> http://jupyter-notebook.readthedocs.io/en/stable/comms.html >>> >>> And I am getting the error >>> >>> utils.js:910 Could not open comm -- Error: Class my_comm_target not >>> found in registry >>> at utils.js:874 >>> at new Promise (<anonymous>) >>> at Object.load_class (utils.js:859) >>> at CommManager.comm_open (comm.js:84) >>> at i (jquery.min.js:4) >>> at Kernel._handle_iopub_message (kernel.js:1223) >>> at Kernel._finish_ws_message (kernel.js:1015) >>> at kernel.js:1006 >>> at <anonymous> >>> (anonymous) @ utils.js:910 >>> Promise rejected (async) >>> CommManager.comm_open @ comm.js:85 >>> i @ jquery.min.js:4 >>> Kernel._handle_iopub_message @ kernel.js:1223 >>> Kernel._finish_ws_message @ kernel.js:1015 >>> (anonymous) @ kernel.js:1006 >>> Promise resolved (async) >>> Kernel._handle_ws_message @ kernel.js:1006 >>> i @ jquery.min.js:4 >>> >>> I have have a custom javascript file called glowcomm.js that is >>> installed at the location >>> >>> nbextensions/vpython_libraries/glowcomm.js >>> >>> The javascript code comes from a python package called vpython that >>> installs some custom javascript code to this location using >>> >>> notebook.nbextensions.install_nbextension(path = >>> package_dir+"/vpython_libraries",overwrite = True,user = True,verbose = 0) >>> >>> >>> The contents of the glowcomm.js file looks like >>> >>> define(["nbextensions/vpython_libraries/jquery-ui.custom.min", >>> "nbextensions/vpython_libraries/glow.min"], function() { >>> >>> var comm >>> >>> IPython.notebook.kernel.comm_manager.register_target('my_comm_target', >>> >>> What do I need to do to register "my_comm_target" so that I don't get >>> this error. >>> >>> Error: Class my_comm_target not found in registry >>> >>> >>> >>> Thanks >>> >>> John >>> >>> >>> -- >>> 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/630e2d49-96e9-4f88-b927-42c36dfcf883%40googlegroups.com >>> <https://groups.google.com/d/msgid/jupyter/630e2d49-96e9-4f88-b927-42c36dfcf883%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- > 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/b4f41f6a-1a49-4d52-ba85-b14ab1c5f165%40googlegroups.com > <https://groups.google.com/d/msgid/jupyter/b4f41f6a-1a49-4d52-ba85-b14ab1c5f165%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CAPDWZHxADn2YigWq-FhcJKA16AA6p2R40vz6J1PcgB2vku7dTA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
