Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Launch in jupyterlite #558

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"binderhub_url": "https://mybinder.org",
"colab_url": "https://colab.research.google.com/",
"deepnote_url": "https://deepnote.com/",
"retrolite_url": "/lite/retro/notebooks/",
"notebook_interface": "jupyterlab",
"thebe": True,
# "jupyterhub_url": "https://datahub.berkeley.edu", # For testing
Expand Down
49 changes: 49 additions & 0 deletions docs/launch.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,56 @@ html_theme_options = {
This will create a new Deepnote project every time you click the launch button.
```

## JupyterLite and RetroLite

```{warning}
JupyterLite and RetroLite are experimental, and their behavior and configuration
may change over time!
Please provide feedback and suggestions.
```

To add [RetroLite](https://jupyterlite-sphinx.readthedocs.io/en/latest/retrolite.html) links to your page, add the following configuration:

```python
html_theme_options = {
...
"launch_buttons": {
"retrolite_url": "/lite/retro/notebooks/"
},
...
}
```
[JupyterLite](https://jupyterlite.readthedocs.io/) allows you to run a Jupyter environment entirely in the browser via [WebAssembly](https://webassembly.org/) and [Pyodide](https://pyodide.org/en/stable/).
To use JupyterLite in your launch buttons, you'll first need to take these steps:
1. **Install [`jupyterlite-sphinx`](https://jupyterlite-sphinx.readthedocs.io/)**. And configure it to publish a JupyterLab environment as part of your published Jupyter Book environment by [following the installation instructions](https://jupyterlite-sphinx.readthedocs.io/en/latest/installation.html).
2. **Configure JupyterLite Sphinx to use your site content as a folder**. You can configure JupyterLite Sphinx to look for notebooks in a specified directory. Put the notebooks you wish to expose in that directory, and [follow these configuration instructions](https://jupyterlite-sphinx.readthedocs.io/en/latest/configuration.html#jupyterlite-content).
```
There are two different interfaces that you can activate with JupyterLite, each is described below.
### JupyterLab via JupyterLite
To add JupyterLab via JupyterLite to your launch buttons, use the following configuration:
```python
html_theme_options = {
...
"launch_buttons": {
"jupyterlite_url": "/lite/lab/notebooks/"
},
...
}
```
Where `notebooks/` is a folder with a collection of Jupyter Notebooks you'd like to serve with JupyterLite.
### RetroLab via JupyterLite
RetroLab mimics the classic Jupyter Notebook interface, but using JupyterLab components.
It will be the default Notebook interface in the near future.
To add RetroLab via JupyterLite to your launch buttons, use the following configuration:
```python
html_theme_options = {
...
"launch_buttons": {
"jupyterlite_url": "/lite/retro/notebooks/"
},
...
}
```
## Live code cells with Thebe

[Thebe](http://thebe.readthedocs.org/) converts your static code blocks into
Expand Down
15 changes: 15 additions & 0 deletions src/sphinx_book_theme/header_buttons/launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ def add_launch_buttons(
binderhub_url = launch_buttons.get("binderhub_url", "").strip("/")
colab_url = launch_buttons.get("colab_url", "").strip("/")
deepnote_url = launch_buttons.get("deepnote_url", "").strip("/")
# retrolite_url could be absolute but without a domain, so we only
# strip trailing slashes, not leading ones
retrolite_url = launch_buttons.get("retrolite_url", "").rstrip("/")
if binderhub_url:
url = (
f"{binderhub_url}/v2/gh/{org}/{repo}/{branch}?"
Expand Down Expand Up @@ -161,6 +164,18 @@ def add_launch_buttons(
}
)

if retrolite_url:
url = f"{retrolite_url}?path={path_rel_repo}"
launch_buttons_list.append(
{
"type": "link",
"text": "RetroLite",
"tooltip": "Launch via RetroLite",
"icon": "_static/images/logo_jupyterlite.svg",
"url": url,
}
)

# Add thebe flag in context
if launch_buttons.get("thebe", False):
launch_buttons_list.append(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions tests/sites/base/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"jupyterhub_url": "https://datahub.berkeley.edu",
"colab_url": "https://colab.research.google.com",
"deepnote_url": "https://deepnote.com",
"retrolite_url": "/lite/retro/notebooks/",
"notebook_interface": "jupyterlab",
"thebe": True,
},
Expand Down