set_next_input() and execute next input from Python

235 views
Skip to first unread message

Florian Wetschoreck

unread,
Nov 30, 2018, 5:10:48 AM11/30/18
to Project Jupyter
Hi,

I want to set the input for the next cell and afterwards execute the next cell.

Currently, I can write in my Python cell:

get_ipython().set_next_input("print('Hello World')")


But this only fills the next input. How can I also execute the next cell from my current cell using Python?

Any help is highly appreciated!

Florian




Florian Wetschoreck

unread,
Nov 30, 2018, 5:13:01 AM11/30/18
to Project Jupyter
Small extension/clarification:

I want this to work in JupyterLab. (In JupyterNotebook I can just execute the next cell with Javascript.)

MinRK

unread,
Dec 5, 2018, 5:59:28 AM12/5/18
to Project Jupyter
I don't believe JupyterLab allows this kind of frontend-action triggered from the kernel, at least not at this point. I think you would have to install a jupyterlab plugin to enable the necessary hooks.

--
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/4ed95124-f02a-4ccf-a1c2-de23ce3b2b39%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Florian Wetschoreck

unread,
Dec 7, 2018, 10:21:13 AM12/7/18
to Project Jupyter
Thank you for your answer!

I am also thinking about a jupyterlab plugin which enables the communication with the Kernel.
However, I am unsure on how to exactly "trigger" the custom plugin.

So, imagine, I have a Python script. And when I run this script or a line of Python (maybe the script is also located in a library), I want this to not only execute the current cell but also paste code into the next cell AND execute the next cell. Because I am basically "auto-generating" multiple separate outputs for the user.

One possible solution that I see right now is that my custom plugin could listen to the execution of cells and check if there is some special code inside and then trigger some custom Javascript action to add a new cell, fill it with necessary code and execute it.
However, this does not feel right. Also, the content of the next cell might be variable based on the results of the "initial" cell.

Is there a better way of triggering my plugin from Python code for this specific scenario? In the ideal case, I can call a function in my extension and pass it some arguments from Python. This seems similar to a display() call where another extension is triggered to handle the display of the output. So, this seems related but maybe not completely?
Reply all
Reply to author
Forward
0 new messages