Skip to content

Commit 4f27380

Browse files
ENH: Add JupyterLite-powered shell for the website (reprise of #47428) (#60758)
Co-authored-by: Jeremy Tuloup <jtp@jtp.io>
1 parent 010ffe2 commit 4f27380

9 files changed

+98
-5
lines changed

.github/workflows/docbuild-and-upload.yml

+4
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ jobs:
5959
- name: Build documentation
6060
run: doc/make.py --warnings-are-errors
6161

62+
- name: Build the interactive terminal
63+
working-directory: web/interactive_terminal
64+
run: jupyter lite build
65+
6266
- name: Build documentation zip
6367
run: doc/make.py zip_html
6468

environment.yml

+7
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ dependencies:
116116
- requests
117117
- pygments # Code highlighting
118118

119+
# web interactive REPL
120+
# see the following links for more context:
121+
# 1. https://jupyterlite-pyodide-kernel.readthedocs.io/en/stable/#compatibility
122+
# 2. https://pyodide.org/en/stable/usage/packages-in-pyodide.html
123+
- jupyterlite-core
124+
- jupyterlite-pyodide-kernel
125+
119126
- pip:
120127
- adbc-driver-postgresql>=0.10.0
121128
- adbc-driver-sqlite>=0.8.0

requirements-dev.txt

+2
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ feedparser
8585
pyyaml
8686
requests
8787
pygments
88+
jupyterlite-core
89+
jupyterlite-pyodide-kernel
8890
adbc-driver-postgresql>=0.10.0
8991
adbc-driver-sqlite>=0.8.0
9092
typing_extensions; python_version<"3.11"

web/interactive_terminal/README.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# The interactive `pandas` REPL
2+
3+
An interactive REPL to easily try `pandas` in the browser, powered by JupyterLite.
4+
5+
![image](https://user-images.githubusercontent.com/591645/175000291-e8c69f6f-5f2c-48d7-817c-cff05ab2cde9.png)
6+
7+
## Build
8+
9+
The interactive REPL is built with the `jupyter lite` CLI.
10+
11+
First make sure `jupyterlite` and a kernel are installed:
12+
13+
```bash
14+
python -m pip install jupyterlite-core
15+
python -m pip install jupyterlite-pyodide-kernel
16+
```
17+
18+
Then in `web/interactive_terminal`, run the following command:
19+
20+
```bash
21+
jupyter lite build
22+
```
23+
24+
## Configuration
25+
26+
This folder contains configuration files for the interactive terminal powered by JupyterLite:
27+
28+
- `jupyter_lite_config.json`: build time configuration, used when building the assets with the `jupyter lite build` command
29+
- `jupyter-lite.json` run time configuration applied when launching the application in the browser
30+
31+
This interactive `pandas` JupyterLite deployment enables a couple of optimizations to only include the `repl` app in the generated static assets, and disables source maps, which can make the assets smaller and faster to load, at the cost of
32+
debugging capabilities.
33+
34+
To learn more about it, check out the JupyterLite documentation:
35+
36+
- Optimizations: https://jupyterlite.readthedocs.io/en/latest/howto/configure/advanced/optimizations.html
37+
- JupyterLite schema: https://jupyterlite.readthedocs.io/en/latest/reference/schema-v0.html
38+
- CLI reference: https://jupyterlite.readthedocs.io/en/latest/reference/cli.html
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"jupyter-lite-schema-version": 0,
3+
"jupyter-config-data": {
4+
"appName": "Pandas REPL",
5+
"appUrl": "./repl",
6+
"enableMemoryStorage": true,
7+
"settingsStorageDrivers": ["memoryStorageDriver"],
8+
"contentsStorageDrivers": ["memoryStorageDriver"]
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"LiteBuildConfig": {
3+
"apps": ["repl"],
4+
"no_unused_shared_packages": true,
5+
"output_dir": "../build/lite",
6+
"no_sourcemaps": true
7+
}
8+
}

web/pandas/getting_started.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,23 @@ by [Wes McKinney](https://wesmckinney.com/), creator of pandas.
2222

2323
## Videos
2424

25-
<iframe width="560" height="315" frameborder="0"
26-
src="https://www.youtube.com/embed/_T8LGqJtuGc"
27-
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
28-
allowfullscreen></iframe>
25+
<iframe
26+
src="https://www.youtube.com/embed/_T8LGqJtuGc"
27+
style="width: 100%; max-width: 560px; height: 315px;"
28+
frameborder="0"
29+
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
30+
allowfullscreen
31+
></iframe>
2932
3033
## Cheat sheet
3134

3235
[pandas cheat sheet](https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf)
36+
37+
## Try pandas in your browser (experimental)
38+
39+
You can try pandas in your browser with the following interactive shell
40+
without needing to install anything on your system.
41+
42+
<p>
43+
<a class="btn btn-primary" href="{{ base_url }}try.html">Try it in your browser</a>
44+
</p>

web/pandas/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ <h1>pandas</h1>
1818
<div class="col-md-4">
1919
<h5>Getting started</h5>
2020
<ul>
21-
<!-- <li><a href="{{ base_url }}/try.html">Try pandas online</a></li> -->
2221
<li><a href="{{ base_url }}getting_started.html">Install pandas</a></li>
2322
<li><a href="{{ base_url }}docs/getting_started/index.html">Getting started</a></li>
23+
<li><a href="{{ base_url }}try.html">Try pandas online</a></li>
2424
</ul>
2525
</div>
2626
<div class="col-md-4">

web/pandas/try.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Try pandas in your browser (experimental)
2+
3+
Try our experimental [JupyterLite](https://jupyterlite.readthedocs.io/en/stable/) live shell with `pandas`, powered by [Pyodide](https://pyodide.org/en/stable/).
4+
5+
**Please note it can take a while (>30 seconds) before the shell is initialized and ready to run commands.**
6+
7+
**Running it requires a reasonable amount of bandwidth and resources (>70 MiB on the first load), so it may not work properly on all devices or networks.**
8+
9+
<iframe
10+
src="./lite/repl/index.html?toolbar=1&kernel=python&execute=0&code=import%20pandas%20as%20pd%0Adf%20%3D%20pd.DataFrame%28%7B%22num_legs%22%3A%20%5B2%2C%204%5D%2C%20%22num_wings%22%3A%20%5B2%2C%200%5D%7D%2C%20index%3D%5B%22falcon%22%2C%20%22dog%22%5D%29%0Adf"
11+
style="width: 100%; max-width: 650px; height: 600px; border: 1px solid #130753;"
12+
></iframe>

0 commit comments

Comments
 (0)