Skip to content

Commit e9c69d3

Browse files
authored
separate prerun installation and prerun-code (#503)
1 parent fe3844b commit e9c69d3

File tree

4 files changed

+6965
-5084
lines changed

4 files changed

+6965
-5084
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ yarn-error.log*
3535

3636
# Jupyter Notebook
3737
.ipynb_checkpoints
38+
.yarn

.yarnrc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
nodeLinker: node-modules

src/components/repl.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,17 @@ import { nord } from 'react-syntax-highlighter/dist/cjs/styles/prism'
55

66
//TODO: We could remove xarrray installation step by requesting xarray to be added to the Pyodide standard lib
77
//TODO: Or wait until jupyterlite has streamlined the installation process of user-specified packages
8+
9+
// use for install xarray via micropip
10+
const preRun =
11+
'import%20micropip%0Aawait%20micropip.install%28%5B%27xarray%27%2C%20%27matplotlib%27%5D%29'
12+
813
// See: https://github.com/jupyterlite/jupyterlite/issues/151
9-
const preRunCode = `%22%22%22%0AThe%20next%20two%20commands%20are%20only%20needed%20on%20this%20webpage%0APlease%20do%20not%20try%20to%20run%20them%20outside%20of%20this%20webpage%2C%20otherwise%20you%20will%20get%20an%20error%0A%22%22%22%0Aimport%20micropip%0Aawait%20micropip.install%28%5B%27xarray%27%2C%20%27matplotlib%27%5D%29%0A%0A%23%20Import%20packages%0Aimport%20xarray%20as%20xr%0Aimport%20numpy%20as%20np%0Aimport%20pandas%20as%20pd%0A%25matplotlib%20inline`
14+
const preRunCode = `%23%20Import%20packages%0Aimport%20xarray%20as%20xr%0Aimport%20numpy%20as%20np%0Aimport%20pandas%20as%20pd%0A%25matplotlib%20inline`
15+
16+
// https://github.com/jobovy/jupyterlite-repl-prerun
17+
const jupyterliteInstance =
18+
'https://jupyterlite-repl-prerun.readthedocs.io/en/latest/lite/repl'
1019

1120
const sampleCode = `"""
1221
To try Xarray in the browser,
@@ -82,7 +91,7 @@ export const Repl = () => {
8291
<AspectRatio ratio={4 / 3}>
8392
<iframe
8493
title='repl'
85-
src={`https://jupyterlite.github.io/demo/repl/?toolbar=1&kernel=python&code=${preRunCode}`}
94+
src={`${jupyterliteInstance}/?toolbar=1&kernel=python&prerun=${preRun}&prerun-code=${preRunCode}`}
8695
alt='demo'
8796
/>
8897
</AspectRatio>

0 commit comments

Comments
 (0)