quarto-ext / shinylive

Quarto extension to embed Shinylive for Python applications
https://quarto-ext.github.io/shinylive/
MIT License
141 stars 7 forks source link

Can one load custom wheel files? (pyodide-built; out of tree) #5

Open zachcp opened 1 year ago

zachcp commented 1 year ago

Hi Team Py-Shiny,

This is really amazing work; thank you. I am wondering if there current the capability to sideload pyodide-built .whl into the environment. I see something similar is done with the requirements.txt file in the py-shiny repo and would hope to be able to do the something similar here.

Thanks, zach cp

wch commented 1 year ago

Yes, you can do it by adding a requirements.txt file with something like this:

```{shinylive-python}
#| standalone: true
## file: app.py

<App contents here>

## file: requirements.txt
mypackage
mypackage2==1.01


Note that, by default it will install the packages from PyPI, but you can also specify a URL. See the live example here:
https://shinylive.io/py/examples/#extra-packages
zachcp commented 1 year ago

Thank you, thats fantastic.

And what would you recommend if the wheels are local. For example, in the standalone shinylive context I can specify a local file (or copy it into /shinylive/pyodide) but that won't work here.

# example requirements.txt
./packages/pack1.whl
./packages/dep1.whl
./packages/dep2.whl

I also notice this route won't work with pyodide packages that are not in the core shinylive distribution. For example, the biopython requirement is not followed and will throw an error.

#| standalone: true
## file: app.py

from Bio.Seq import Seq
print(Seq("AACTG")) 

## file: requirements.txt
biopython

This will yield the following:

Traceback (most recent call last):
  File "<exec>", line 202, in _start_app
  File "/lib/python3.10/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/pyodide/app_zmur716jvalmlsxccz4r/app.py", line 2, in <module>
    from Bio import SeqIO
ModuleNotFoundError: No module named 'Bio'