How to use @jupyterlab/notebook - 10 common examples

To help you get started, we’ve selected a few @jupyterlab/notebook examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / tests / test-notebook / src / actions.spec.ts View on Github external
it('should run the selected cells ', async () => {
        const next = widget.widgets[1] as MarkdownCell;
        widget.select(next);
        const cell = widget.activeCell as CodeCell;
        cell.model.outputs.clear();
        next.rendered = false;
        const result = await NotebookActions.runAndAdvance(widget, session);
        expect(result).to.equal(true);
        expect(cell.model.outputs.length).to.be.above(0);
        expect(next.rendered).to.equal(true);
      }).timeout(30000); // Allow for slower CI
github jupyterlab / jupyterlab / tests / test-notebook / src / actions.spec.ts View on Github external
it('should stop executing code cells on an error', async () => {
        widget.activeCell.model.value.text = ERROR_INPUT;
        const cell = widget.model.contentFactory.createCodeCell({});
        widget.model.cells.push(cell);
        widget.select(widget.widgets[widget.widgets.length - 1]);
        const result = await NotebookActions.runAndAdvance(widget, ipySession);
        expect(result).to.equal(false);
        expect(cell.executionCount).to.be.null;
        await ipySession.kernel.restart();
      }).timeout(30000); // Allow for slower CI
github jupyterlab / jupyterlab-data-explorer / tests / test-notebook / src / actions.spec.ts View on Github external
it('should render all markdown cells on an error', async () => {
        widget.activeCell.model.value.text = ERROR_INPUT;
        const cell = widget.widgets[1] as MarkdownCell;
        cell.rendered = false;
        const result = await NotebookActions.runAll(widget, ipySession);
        // Markdown rendering is asynchronous, but the cell
        // provides no way to hook into that. Sleep here
        // to make sure it finishes.
        await sleep(100);
        expect(result).to.equal(false);
        expect(cell.rendered).to.equal(true);
        await ipySession.kernel.restart();
      }).timeout(60000); // Allow for slower CI
    });
github jupyterlab / jupyterlab / tests / test-notebook / src / actions.spec.ts View on Github external
it('should stop executing code cells on an error', async () => {
        widget.activeCell.model.value.text = ERROR_INPUT;
        const cell = widget.model.contentFactory.createCodeCell({});
        widget.model.cells.push(cell);
        const result = await NotebookActions.runAll(widget, ipySession);
        expect(result).to.equal(false);
        expect(cell.executionCount).to.be.null;
        expect(widget.activeCellIndex).to.equal(widget.widgets.length - 1);
        await ipySession.kernel.restart();
      }).timeout(30000); // Allow for slower CI
github jupyterlab / jupyterlab-data-explorer / tests / test-notebook / src / actions.spec.ts View on Github external
it('should stop executing code cells on an error', async () => {
        let cell = widget.model.contentFactory.createCodeCell({});
        cell.value.text = ERROR_INPUT;
        widget.model.cells.insert(2, cell);
        widget.select(widget.widgets[2]);
        cell = widget.model.contentFactory.createCodeCell({});
        widget.model.cells.push(cell);
        widget.select(widget.widgets[widget.widgets.length - 1]);
        const result = await NotebookActions.run(widget, ipySession);
        expect(result).to.equal(false);
        expect(cell.executionCount).to.be.null;
        await ipySession.kernel.restart();
      }).timeout(30000); // Allow for slower CI
github jupyterlab / jupyterlab / tests / test-notebook / src / actions.spec.ts View on Github external
it('should stop executing code cells on an error', async () => {
        let cell = widget.model.contentFactory.createCodeCell({});
        cell.value.text = ERROR_INPUT;
        widget.model.cells.insert(2, cell);
        widget.select(widget.widgets[2]);
        cell = widget.model.contentFactory.createCodeCell({});
        widget.model.cells.push(cell);
        widget.select(widget.widgets[widget.widgets.length - 1]);
        const result = await NotebookActions.run(widget, ipySession);
        expect(result).to.equal(false);
        expect(cell.executionCount).to.be.null;
        await ipySession.kernel.restart();
      }).timeout(30000); // Allow for slower CI
github spyder-ide / spyder-notebook / spyder_notebook / server / src / index.ts View on Github external
})
  });

  let opener = {
    open: (widget: Widget) => {
      // Do nothing for sibling widgets for now.
    }
  };

  let docRegistry = new DocumentRegistry();
  let docManager = new DocumentManager({
    registry: docRegistry,
    manager,
    opener
  });
  let mFactory = new NotebookModelFactory({});
  let editorFactory = editorServices.factoryService.newInlineEditor;
  let contentFactory = new NotebookPanel.ContentFactory({ editorFactory });

  let wFactory = new NotebookWidgetFactory({
    name: 'Notebook',
    modelName: 'notebook',
    fileTypes: ['notebook'],
    defaultFor: ['notebook'],
    preferKernel: true,
    canStartKernel: true,
    rendermime,
    contentFactory,
    mimeTypeService: editorServices.mimeTypeService
  });
  docRegistry.addModelFactory(mFactory);
  docRegistry.addWidgetFactory(wFactory);
github jupyterlab / jupyterlab-data-explorer / jupyterlab / examples / notebook / src / index.ts View on Github external
})
  });

  let opener = {
    open: (widget: Widget) => {
      // Do nothing for sibling widgets for now.
    }
  };

  let docRegistry = new DocumentRegistry();
  let docManager = new DocumentManager({
    registry: docRegistry,
    manager,
    opener
  });
  let mFactory = new NotebookModelFactory({});
  let editorFactory = editorServices.factoryService.newInlineEditor;
  let contentFactory = new NotebookPanel.ContentFactory({ editorFactory });

  let wFactory = new NotebookWidgetFactory({
    name: 'Notebook',
    modelName: 'notebook',
    fileTypes: ['notebook'],
    defaultFor: ['notebook'],
    preferKernel: true,
    canStartKernel: true,
    rendermime,
    contentFactory,
    mimeTypeService: editorServices.mimeTypeService
  });
  docRegistry.addModelFactory(mFactory);
  docRegistry.addWidgetFactory(wFactory);
github jupyterlab / jupyterlab / examples / notebook / src / index.ts View on Github external
// Do nothing for sibling widgets for now.
    }
  };

  let docRegistry = new DocumentRegistry();
  let docManager = new DocumentManager({
    registry: docRegistry,
    manager,
    opener
  });
  let mFactory = new NotebookModelFactory({});
  let editorFactory = editorServices.factoryService.newInlineEditor.bind(
    editorServices.factoryService);
  let contentFactory = new NotebookPanel.ContentFactory({ editorFactory });

  let wFactory = new NotebookWidgetFactory({
    name: 'Notebook',
    modelName: 'notebook',
    fileExtensions: ['.ipynb'],
    defaultFor: ['.ipynb'],
    preferKernel: true,
    canStartKernel: true,
    rendermime, contentFactory,
    mimeTypeService: editorServices.mimeTypeService
  });
  docRegistry.addModelFactory(mFactory);
  docRegistry.addWidgetFactory(wFactory);

  let nbWidget = docManager.open(NOTEBOOK) as NotebookPanel;
  let palette = new CommandPalette({ commands });

  const editor = nbWidget.notebook.activeCell && nbWidget.notebook.activeCell.editor;
github yuvipanda / simplest-notebook / packages / notebook-extension / src / index.ts View on Github external
function activateNotebookHandler(app: JupyterLab, mainMenu: IMainMenu, palette: ICommandPalette, contentFactory: NotebookPanel.IContentFactory, editorServices: IEditorServices, restorer: ILayoutRestorer, rendermime: IRenderMimeRegistry, settingRegistry: ISettingRegistry, browserFactory: IFileBrowserFactory | null, launcher: ILauncher | null): INotebookTracker {
  const services = app.serviceManager;
  // An object for tracking the current notebook settings.
  let editorConfig = StaticNotebook.defaultEditorConfig;
  const factory = new NotebookWidgetFactory({
    name: FACTORY,
    fileTypes: ['notebook'],
    modelName: 'notebook',
    defaultFor: ['notebook'],
    preferKernel: true,
    canStartKernel: true,
    rendermime: rendermime,
    contentFactory,
    editorConfig,
    mimeTypeService: editorServices.mimeTypeService
  });
  const { commands, restored } = app;
  const tracker = new NotebookTracker({ namespace: 'notebook' });

  // Handle state restoration.
  restorer.restore(tracker, {