8000 py-env · YComputer/pyscript@9976041 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9976041

Browse files
committed
py-env
1 parent 9cf9da8 commit 9976041

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

GETTING-STARTED.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,42 @@ pyscript.write('pi', f'π is approximately {pi:.3f}')
111111
</html>
112112
```
113113

114+
## Packages and modules
114115

116+
In addition to the [Python Standard Library](https://docs.python.org/3/library/) and
117+
the `pyscript` module, many 3rd-party OSS packages will work out-of-the-box with PyScript.
118+
In order to use them you will need to delcare the dependencies using the `<py-env>` in the
119+
HTML head.
115120

116-
## Asynchronous
121+
For example, NumPy and Matplotlib are available. Notice here we're using `<py-script output="plot">`
122+
as a shortcut, which takes the expression on the last line of the script and runs `pyscript.write('plot', fig)`.
123+
124+
125+
```html
126+
<html>
127+
<head>
128+
<link rel="stylesheet" href="pyscript.css" />
129+
<script defer src="pyscript.js"></script>
130+
<py-env>
131+
- numpy
132+
- matplotlib
133+
</py-env>
134+
</head>
135+
136+
<body>
137+
<h1>Let's plot random numbers</h1>
138+
<div id="plot"></div>
139+
<py-script output="plot">
140+
import matplotlib.pyplot as plt
141+
import numpy as np
142+
143+
x = np.random.randn(1000)
144+
y = np.random.randn(1000)
145+
146+
fig, ax = plt.subplots()
147+
ax.scatter(x, y)
148+
fig
149+
</py-script>
150+
</body>
151+
</html>
152+
```

0 commit comments

Comments
 (0)
0