NikhilP

Untitled

May 25th, 2021
764
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. cd ..
  2. conda deactivate
  3. rm -r -f myextension/
  4. conda remove -n jupyterlab-ext --all -y
  5.  
  6. #################################################################
  7.  
  8. cd /mnt/c/Users/nikhil.patil/Desktop/Jupyter\ Debugger/
  9. conda activate jupyterlab-ext
  10. jupyter lab
  11.  
  12. #################################################################
  13.  
  14. conda create -n jupyterlab-ext -y --override-channels --strict-channel-priority -c conda-forge -c anaconda jupyterlab=3 cookiecutter nodejs jupyter-packaging pandas ipywidgets
  15. conda activate jupyterlab-ext
  16. cd /mnt/c/Users/nikhil.patil/Desktop/Jupyter\ Debugger
  17. cookiecutter https://github.com/jupyterlab/extension-cookiecutter-ts
  18. # Do the cookie setup, I set everything to default
  19. cd myextension/
  20. # add following to package.json *dependencies*
  21. "@jupyterlab/application": "^3.0.11",
  22. "@jupyterlab/apputils": "^3.0.9",
  23. "@jupyterlab/coreutils": "^5.0.6",
  24. "@jupyterlab/docregistry": "^3.0.11",
  25. "@jupyterlab/notebook": "^3.0.11",
  26. "@lumino/disposable": "^1.7.0"
  27. OR
  28. #execute these in cmd. following gets the latest versions (currently same as above)
  29. jlpm add @jupyterlab/application
  30. jlpm add @jupyterlab/apputils
  31. jlpm add @jupyterlab/coreutils
  32. jlpm add @jupyterlab/docregistry
  33. jlpm add @jupyterlab/notebook
  34. jlpm add @lumino/disposable
  35. jlpm
  36. # insert button.ts to src folder (also updated the console log in index.ts)
  37. # insert the button info to index.ts
  38. jlpm build
  39. # since jupyter labextension install . keeps failing, this is the only way I can install it rn
  40. jupyter labextension develop --overwrite .
  41. jupyter lab
  42. # extension is available and shows as installed on jupyter lab
  43. # My Button is visible when you start a new notebook
  44.  
  45.  
  46. ############################### index.ts ###############################
  47. import {
  48. JupyterFrontEnd,
  49. JupyterFrontEndPlugin
  50. } from '@jupyterlab/application';
  51.  
  52. import {ButtonExtension} from "./button";
  53.  
  54. /**
  55. * Initialization data for the myextension extension.
  56. */
  57. const extension: JupyterFrontEndPlugin<void> = {
  58. id: 'myextension:plugin',
  59. autoStart: true,
  60. activate: (app: JupyterFrontEnd) => {
  61. console.log('JupyterLab extension myextension is activated Nikhil P!');
  62. let buttonExtension = new ButtonExtension();
  63. app.docRegistry.addWidgetExtension('Notebook', buttonExtension);
  64. console.log('JupyterLab extension myextension is activated Nikhil Patil!');
  65. }
  66. };
  67.  
  68. export default extension;
  69.  
  70.  
  71. ############################### button.ts ###############################
  72. import { ToolbarButton } from "@jupyterlab/apputils";
  73. import { DocumentRegistry } from "@jupyterlab/docregistry";
  74. import { INotebookModel, NotebookPanel } from "@jupyterlab/notebook";
  75. import { IDisposable } from "@lumino/disposable";
  76.  
  77. export class ButtonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
  78.  
  79. createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
  80. // Create the toolbar button
  81. let mybutton = new ToolbarButton({
  82. label: 'My Button',
  83. onClick: () => alert('You did it!')
  84. });
  85.  
  86. // Add the toolbar button to the notebook toolbar
  87. panel.toolbar.insertItem(10, 'mybutton', mybutton);
  88.  
  89. // The ToolbarButton class implements `IDisposable`, so the
  90. // button *is* the extension for the purposes of this method.
  91. return mybutton;
  92. }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment