Best way to integrate a Kernel with a React Widget in a JupyterLab Extension

Hello everyone,

I’m working on an extension which consists in a React Widget.

Looking at different extension examples I had created a Factory to create my widget and everything works fine. I defined the following behavior of opening the widget for the .pipeline files:

        // Add the default behavior of opening the widget for .pipeline files
        app.docRegistry.addFileType(
          {
            name: 'react-pipeline',
            displayName: 'Pipeline',
            extensions: ['.pipeline'],
            icon: pipelineIcon,
            fileFormat: 'text'
          },
          [PIPELINE_FACTORY, 'JSON']
        );
        app.docRegistry.addWidgetFactory(pipelineEditorFactory);

And my PipelineEditorFactory extends ABCWidgetFactory.

export class PipelineEditorFactory extends ABCWidgetFactory<DocumentWidget> { ... }

I now want to attach a Kernel to my extension alongside the React Widget. I am using this example.
If I understood correctly I need to create a panel which will tie together a Widget and a Kernel session.

I’m wondering what’s the best strategy to refactor my code to address the addition of the Kernel. Should I create a different Factory that will create panels (which in turns create a new Kernel session and Widget) when opening .pipeline files ? If so, what type of Factory ?

Do I need to use a Panel? Could I attach a session to a Widget?

Any pointers would be helpful, thank you in advance.

1 Like

UP! Just in case it got lost with the new topics :slight_smile:
Thank you :pray:

You do not need to create a panel to create a kernel session. I guess that your question narrows down to how to get SessionContext in a subclass of ABCWidgetFactory; you will get it passed down to createNew(context: IContext) method in the context. The context has sessionContext property which is equivalent to the this._sessionContext in the xample you linked.

Does it answer your question?

1 Like

Thank you @krassowski. Really appreciate the help. It’s now way clearer!

So I can pass down the Context via the ABCWidgetFactory. By default I guess there is no SessionContext. So I need to create one so that it is passed down to the factory. I’ll try this out :slight_smile:

Thanks again!