twn
August 23, 2022, 8:54am
1
See the image below:
I want write a jupyter ui extension that adds a new menu item like “Files”, “Running”, and “Clusters”. All of the documentation and examples I’ve seen show how to add extensions to the notebook pages themselves, but I haven’t found anything about how to change the main page.
Can anyone help point me in the write direction? Thanks!
1 Like
I would strongly recommend targeting the new, safer plugin system included in the upcoming notebook v7 (you can check the latest build online, here ); in v7 the tabs are in the same place as before:
and are defined the notebookTreeWidget
plugin which provides INotebookTree
token:
/**
* A plugin to add the file browser widget to an INotebookShell
*/
const notebookTreeWidget: JupyterFrontEndPlugin<INotebookTree> = {
id: '@jupyter-notebook/tree-extension:widget',
requires: [
IFileBrowserFactory,
ITranslator,
ISettingRegistry,
IToolbarWidgetRegistry
],
optional: [IRunningSessionManagers],
autoStart: true,
provides: INotebookTree,
activate: (
app: JupyterFrontEnd,
factory: IFileBrowserFactory,
translator: ITranslator,
settingRegistry: ISettingRegistry,
toolbarRegistry: IToolbarWidgetRegistry,
This file has been truncated. show original
To add a custom tab you would need to request that token and call addWidget()
and tabBar.addTab()
, roughly:
import {
JupyterFrontEnd,
JupyterFrontEndPlugin,
} from '@jupyterlab/application';
import { INotebookTree } from '@jupyter-notebook/tree';
import { Widget } from '@lumino/widgets';
// from https://github.com/jupyterlab/extension-examples/blob/7a0473140860aa407c21d9beafa8ae721f659e70/widgets/README.md
class ExampleWidget extends Widget {
constructor() {
super();
this.addClass('my-extension-example-widget');
this.id = 'simple-widget-example';
this.title.label = 'Widget Example';
this.title.closable = false;
}
}
const plugin: JupyterFrontEndPlugin<void> = {
id: 'my-extension:plugin',
autoStart: true,
requires: [INotebookTree],
activate: (app: JupyterFrontEnd, nbTreeWidget: INotebookTree) => {
const myWidget = new ExampleWidget();
nbTreeWidget.addWidget(myWidget);
nbTreeWidget.tabBar.addTab(myWidget.title);
},
};
export default plugin;
For reference, there is Extension Developer Guide — JupyterLab 3.4.5 documentation ; following the tutorial for JupyterLab extensions which should clarify things. More examples and resources may appear on Custom front-end extensions — Jupyter Notebook 7.0.0a5 documentation with time. If you have any questions let me know.