🪐 Notebook Component
The below picture is an example of Notebook into a React.js component.
This is what it takes to create a Notebook. In this first example, the Jupyter Server will be fetched for the test.ipynb
notebook "ipynb" file content.
<Jupyter terminals={true} collaborative={true}>
<Notebook path="test.ipynb" />
</Jupyter>
Alternatively, you can get a notebook "ipynb" content from any JSON file compatible with the INotebookContent
interface.
import { INotebookContent } from '@jupyterlab/nbformat';
import nbformat from "./NotebookExample.ipynb.json";
<Jupyter terminals={true} collaborative={true}>
<Notebook nbformat={nbformat as INotebookContent} />
</Jupyter>
For IPyWidgets, use the following properties:
bundledIPyWidgets
: List of module name, version and exports.externalIPyWidgets
: List of module name and version to be loaded from public CDNs.ipywidgets
:lab
orclassic
(deprecated, will be soon removed). Please uselab
The available properties for the Notebook component are available on this TypeDoc page.
With a Jupyter server
<Jupyter
jupyterServerUrl="https://oss.datalayer.run/api/jupyter-server"
jupyterServerToken="60c1661cc408f978c309d04157af55c9588ff9557c9380e4fb50785750703da6"
>
<Notebook />
</Jupyter>
You can set the following props to connect it to a running Jupyter Server:
jupyterServerUrl
: The server URLjupyterServerToken
: The server authentication token
Your server will likely need to accept connection from external client.
With in-browser kernel
It supports in-browser kernel (using JupyterLite kernels).
To use the Pyodide Python kernel,
you can simply set lite
to true
:
<Jupyter
lite={true}
>
<Notebook
ipywidgets={'classic'}
{/* Include a default content */}
nbformat={{
cells: [
{
cell_type: 'code',
outputs: [],
source:
"import piplite\nawait piplite.install('ipywidgets')",
},
{
cell_type: 'code',
outputs: [],
source: 'import ipywidgets as widgets\nw = widgets.IntSlider()\nw',
}
],
metadata: {
kernelspec: {
display_name: 'Python 3 (ipykernel)',
language: 'python',
name: 'python3',
},
},
nbformat: 4,
nbformat_minor: 5,
}}
/>
</Jupyter>