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 On Mon, Sep 10, 2018 at 10:42 AM Titus Barik <[email protected]> wrote: > 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. > > -- > 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/1536601350.1530800.1503185984.1A58B039%40webmail.messagingengine.com > . > 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/CAPDWZHzrE2JdD_DeLbR2RPpYfHJ6Bex-6zrM15zzX%2BM%3DD%2Bfm3A%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
