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

Notebook output hosting webview messaging API #92955

Closed
rebornix opened this issue Mar 18, 2020 · 1 comment
Closed

Notebook output hosting webview messaging API #92955

rebornix opened this issue Mar 18, 2020 · 1 comment
Assignees
Labels
Milestone

Comments

@rebornix
Copy link
Member

Why we need this API?

In Jupyter Notebook, users can use ipywidget to render interactive widgets as outputs. This can be supported easily by custom renderer API which converts the JSON output to HTML fragments and then the core will render it the webview. However, in Jupyter Notebook, ipywidget can talk to the kernel through the same sockets which it uses to run code cells

image

As you can see from above image, ipywidget will create a comm object which uses the Kernel Frontend proxy to communicate with the comm object in the kernel.

How to support ipywidget

The ipywidget is similar to vega and plotly, it can be supported by custom renderers. But to allow the ipywidget rendered in the webview to communicate with the kernel, we need to expose the messaging channel on webview, the same way we do for the Webview API.

One proposal is adding two APIs on NotebookEditor

export interface NotebookEditor {
	readonly document: NotebookDocument;
	viewColumn?: ViewColumn;
+	/**
+	 * Fired when the output hosting webview posts a message.
+	 */
+	readonly onDidReceiveMessage: Event<any>;
+	/**
+	 * Post a message to the output hosting webview.
+	 *
+	 * Messages are only delivered if the editor is live.
+	 *
+	 * @param message Body of the message. This must be a string or other json serilizable object.
+	 */
+	postMessage(message: any): Thenable<boolean>;
	/**
	 * Create a notebook cell. The cell is not inserted into current document when created. Extensions should insert the cell into the document by [TextDocument.cells](#TextDocument.cells)
	 */
	createCell(content: string, language: string, type: CellKind, outputs: CellOutput[]): NotebookCell;
}
@rebornix
Copy link
Member Author

Webview API already exposed through NotebookEditor

@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant