Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cd ..
- conda deactivate
- rm -r -f myextension/
- conda remove -n jupyterlab-ext --all -y
- #################################################################
- cd /mnt/c/Users/nikhil.patil/Desktop/Jupyter\ Debugger/
- conda activate jupyterlab-ext
- jupyter lab
- #################################################################
- conda create -n jupyterlab-ext -y --override-channels --strict-channel-priority -c conda-forge -c anaconda jupyterlab=3 cookiecutter nodejs jupyter-packaging pandas ipywidgets
- conda activate jupyterlab-ext
- cd /mnt/c/Users/nikhil.patil/Desktop/Jupyter\ Debugger
- cookiecutter https://github.com/jupyterlab/extension-cookiecutter-ts
- # Do the cookie setup, I set everything to default
- cd myextension/
- # add following to package.json *dependencies*
- "@jupyterlab/application": "^3.0.11",
- "@jupyterlab/apputils": "^3.0.9",
- "@jupyterlab/coreutils": "^5.0.6",
- "@jupyterlab/docregistry": "^3.0.11",
- "@jupyterlab/notebook": "^3.0.11",
- "@lumino/disposable": "^1.7.0"
- OR
- #execute these in cmd. following gets the latest versions (currently same as above)
- jlpm add @jupyterlab/application
- jlpm add @jupyterlab/apputils
- jlpm add @jupyterlab/coreutils
- jlpm add @jupyterlab/docregistry
- jlpm add @jupyterlab/notebook
- jlpm add @lumino/disposable
- jlpm
- # insert button.ts to src folder (also updated the console log in index.ts)
- # insert the button info to index.ts
- jlpm build
- # since jupyter labextension install . keeps failing, this is the only way I can install it rn
- jupyter labextension develop --overwrite .
- jupyter lab
- # extension is available and shows as installed on jupyter lab
- # My Button is visible when you start a new notebook
- ############################### index.ts ###############################
- import {
- JupyterFrontEnd,
- JupyterFrontEndPlugin
- } from '@jupyterlab/application';
- import {ButtonExtension} from "./button";
- /**
- * Initialization data for the myextension extension.
- */
- const extension: JupyterFrontEndPlugin<void> = {
- id: 'myextension:plugin',
- autoStart: true,
- activate: (app: JupyterFrontEnd) => {
- console.log('JupyterLab extension myextension is activated Nikhil P!');
- let buttonExtension = new ButtonExtension();
- app.docRegistry.addWidgetExtension('Notebook', buttonExtension);
- console.log('JupyterLab extension myextension is activated Nikhil Patil!');
- }
- };
- export default extension;
- ############################### button.ts ###############################
- import { ToolbarButton } from "@jupyterlab/apputils";
- import { DocumentRegistry } from "@jupyterlab/docregistry";
- import { INotebookModel, NotebookPanel } from "@jupyterlab/notebook";
- import { IDisposable } from "@lumino/disposable";
- export class ButtonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
- createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
- // Create the toolbar button
- let mybutton = new ToolbarButton({
- label: 'My Button',
- onClick: () => alert('You did it!')
- });
- // Add the toolbar button to the notebook toolbar
- panel.toolbar.insertItem(10, 'mybutton', mybutton);
- // The ToolbarButton class implements `IDisposable`, so the
- // button *is* the extension for the purposes of this method.
- return mybutton;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment