-
Notifications
You must be signed in to change notification settings - Fork 34.5k
Description
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
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;
}