Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I'm trying to figure out a couple of cell operations #1041

Closed
paddymul opened this issue Oct 16, 2024 · 2 comments
Closed

I'm trying to figure out a couple of cell operations #1041

paddymul opened this issue Oct 16, 2024 · 2 comments

Comments

@paddymul
Copy link

I work on a widget that does DataFrame visualization and codegen. I want the widget to be able create a cell immediately below it, and inject then edit code in that cell.

I want to create a new cell, then get a reference to that created cell (by id or something else) then be able to edit that cell.

I have found a code snippet to edit a cell, but I don't know how to edit a cell, or find the cell I just created.

from IPython.core.getipython import get_ipython

def create_new_cell(contents):
    shell = get_ipython()
    payload = dict(
        source='set_next_input',
        text=contents,
        replace=False,
    )
    return shell.payload_manager.write_payload(payload, single=False)

I have reviewed the docs here, and I don't obviously see how to do this?
https://jupyter-client.readthedocs.io/en/latest/messaging.html

Any suggestions?

@davidbrochart
Copy link
Member

jupyter-client doesn't know anything about notebooks. You can probably do that using JupyterLab's notebook API.

@paddymul
Copy link
Author

Thank you. There are so many packages around jupyter that it's not obvious where to search for code or even help.

I started a discourse thread here
https://discourse.jupyter.org/t/im-trying-to-figure-out-a-couple-of-cell-operations-from-python/29276

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants