Jupyter widget that modifies notebook?

27 views
Skip to first unread message

Titus Barik

unread,
Sep 10, 2018, 1:42:34 PM9/10/18
to jup...@googlegroups.com
Hi all,

Apologies for the newbie question.

How does one design a Jupyter widget (DOMWidget) that can modify the notebook itself? For example, given a sample DOMWidget, let's say I want a button that upon clicking inserts a new cell:

define('hello', ["@jupyter-widgets/base"], function(widgets) {

var HelloView = widgets.DOMWidgetView.extend({

// Render the view.
render: function() {
this.el = /* creates some sort of HTML button */;
},
});

return {
HelloView: HelloView
};
});

Is the right thing to do to modify render, render an HTML button, and then have its onclick event perform something like:

IPython.notebook.insert_cell_below('code').set_text('some text');

Or is there some better/more appropriate strategy?

Thanks.

Jason Grout

unread,
Sep 10, 2018, 1:47:29 PM9/10/18
to jup...@googlegroups.com
That or something similar may work as a hack for the classic notebook, but would be much harder to impossible to get to work in JupyterLab, for example. In general, the widgets do not have access to the notebook they are running in.

Jason


--
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.
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/1536601350.1530800.1503185984.1A58B039%40webmail.messagingengine.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages