Help needed: creating a notebook extension

106 views
Skip to first unread message

Logan Page

unread,
Nov 4, 2016, 6:22:29 PM11/4/16
to Project Jupyter
I have more or less figured out what I need to do for an extension I'm creating.

The problem I have at the moment is I need to get a json object from an ipython kernel extension into a notebook extension.

Can someone point me in the right direction for achieving this?

MinRK

unread,
Nov 12, 2016, 4:41:37 PM11/12/16
to Project Jupyter

You can publish Javascript from the kernel with:

from IPython.display import display, Javascript

display(Javascript("""your_js()"""))

That might be what you need.

-MinRK


--
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 jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/4c5f6184-ff4a-4697-a4cb-dc25d4b81664%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Logan Page

unread,
Nov 18, 2016, 4:05:10 PM11/18/16
to Project Jupyter
Hi MinRK

Thanks for the reply.
I don't think this is what I need, then again I am not 100% sure I am going about it the right way.

I have created some ipython cell magics (kernel extension) that populates a json object when a cell is executed.
I need to get this json object into the front-end (javascript notebook extension) once complete.

The hack I am using at the moment is simply to print the json str from ipython and use an "executed.CodeCell" event to wait for the output (print info).





On Saturday, November 12, 2016 at 11:41:37 PM UTC+2, Min RK wrote:

You can publish Javascript from the kernel with:

from IPython.display import display, Javascript

display(Javascript("""your_js()"""))

That might be what you need.

-MinRK

On Fri, Nov 4, 2016 at 3:22 PM, Logan Page <pag...@gmail.com> wrote:
I have more or less figured out what I need to do for an extension I'm creating.

The problem I have at the moment is I need to get a json object from an ipython kernel extension into a notebook extension.

Can someone point me in the right direction for achieving this?

--
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 jupyter+u...@googlegroups.com.

Thomas Kluyver

unread,
Nov 19, 2016, 9:14:50 AM11/19/16
to Project Jupyter
On 18 November 2016 at 21:05, Logan Page <pag...@gmail.com> wrote:
I have created some ipython cell magics (kernel extension) that populates a json object when a cell is executed.
I need to get this json object into the front-end (javascript notebook extension) once complete.

The hack I am using at the moment is simply to print the json str from ipython and use an "executed.CodeCell" event to wait for the output (print info).

One way you could do this is to have your notebook extension define a Javascript callback function and make it globally accessible (which could be by making it a handler for a new event you define, for instance). Then you could wrap the JSON from the kernel in a call to that function and display it as Javascript:

display(Javascript("my_callback_function(%s)" % json.dumps({'object from': 'kernel'})))

This would be called again whenever the notebook is loaded, though, as the displayed Javascript is saved as an output.

A nicer solution involving a bit more work would be to use comms to send your data:
http://jupyter-notebook.readthedocs.io/en/latest/comms.html

Logan Page

unread,
Nov 19, 2016, 4:41:45 PM11/19/16
to Project Jupyter
comms is what I'm looking for thank you :)

Logan Page

unread,
Nov 20, 2016, 7:52:15 AM11/20/16
to Project Jupyter
So, comms took me awhile to figure out, but it seems I have it working albeit a bit hacky.
The extension I am working on is here: https://github.com/lgpage/nbtutor
I would value any feedback or critique.

Thomas Kluyver

unread,
Nov 20, 2016, 8:53:39 AM11/20/16
to Project Jupyter
On 20 November 2016 at 12:52, Logan Page <pag...@gmail.com> wrote:
So, comms took me awhile to figure out, but it seems I have it working albeit a bit hacky.

The page I linked you to was written quite recently when we realised there were no docs describing how to use comms at all. So it's probably not as clear and complete as it could be. I'm glad you were able to work it out, and if you see any ways the documentation could be improved, please let us know.
Reply all
Reply to author
Forward
0 new messages