Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Custom environments #15

Open
psychemedia opened this issue Mar 14, 2024 · 1 comment
Open

[Feature]: Custom environments #15

psychemedia opened this issue Mar 14, 2024 · 1 comment
Labels
p: low Address issue when time permits t: feature-request

Comments

@psychemedia
Copy link

psychemedia commented Mar 14, 2024

Feature Description

I notice that you do some of the lifting to get matplotlib charts to work via JS in each rendered page:

    // Load the `matplotlib` package with necessary environment hook
    await mainPyodide.loadPackage("matplotlib");

    // Set the backend for matplotlib to be interactive.
    await mainPyodide.runPythonAsync(`
    import matplotlib
    matplotlib.use("module://matplotlib_pyodide.html5_canvas_backend")
    from matplotlib import pyplot as plt
    `);

I wonder if it would also be useful to allow config either globally or locally that would allow a user to specify in header or _quarto.yml things like:

- pyodide-pip
  - pandas

which would create something like:

await mainPyodide.loadPackage("pandas");

or optionally something like:

- pyodide-pip
  - pandas, ["import pandas as pd", "pd.options.display.max_rows = 5"]

to generate:

    await mainPyodide.loadPackage("pandas");

    await mainPyodide.runPythonAsync(`
       import pandas as pd
       pd.options.display.max_rows = 5
    `);

Alternatively, keep pyodide-pip as a simple list and then allow:

- pyodide-init
  - import pandas as pd
  - pd.options.display.max_rows = 5
  - etc
@coatless
Copy link
Collaborator

On the first request regarding packages, the plan here is to allow for package loading via packages key, e.g.

pyodide: 
  packages: 
    - package: 'pkg1'
    - package: 'pkg2'
       alias: pd
    - package: 'https://example.com/files/pkg3-2.0.0-py2.py3-none-any.whl'

Packages would be installed via:

import micropip

for pkg in {{packages}}: 
  micropip.install(
      pkg
  )

Then imported using:

import {{pkg}}

or

import {{pkg}} as {{alias}}

For the second request regarding injecting the setup code before the cells are unlocked, we'd likely want to add an include-script-header designation that runs after all packages are installed, e.g.

---
pyodide: 
  include-script-header: | 
    pd.options.display.max_rows = 5
---

@coatless coatless added the p: low Address issue when time permits label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p: low Address issue when time permits t: feature-request
Projects
None yet
Development

No branches or pull requests

2 participants