File tree Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Expand file tree Collapse file tree 1 file changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,42 @@ pyscript.write('pi', f'π is approximately {pi:.3f}')
111
111
</html >
112
112
```
113
113
114
+ ## Packages and modules
114
115
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.
115
120
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
+ ```
You can’t perform that action at this time.
0 commit comments