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

accessing resources with pyodide #82

Open
anielsen001 opened this issue Jan 15, 2025 · 3 comments
Open

accessing resources with pyodide #82

anielsen001 opened this issue Jan 15, 2025 · 3 comments
Labels
documentation Improvements or additions to documentation enhancement New feature or request

Comments

@anielsen001
Copy link

I'm trying to access a directory via the resources option in the yaml header. I have a directory called /opt/project/testdata with one file called blah.txt and I have this quarto file

---
title: Real data examples
format: live-html
pyodide:
  resources:
    - "/opt/project/testdata"
---


```{pyodide}
from os import listdir
print(listdir("testdata"))

```

When I try to run the file, I get an error:

image

Pyodide appears to see the directory I specified because it sees the blah.txt file, but then gets an error trying to load it. I'm using quarto 1.6.40 with the quarto preview command. I checked the file permissions, and everything is wide open (ubuntu). I'm not entirely sure how pyiodide plays with quarto preview. I have quarto render to the default _site directory. Is there some issue related to the render output directory? The testdata directory is not copied there.

@anielsen001
Copy link
Author

I've done some more digging into this. It appears when the qmd file is in a subdirectory of the project and the data directory is relative to the project root, you have to specify the path using something like ../data. Often in quarto you can specify the path relative to the project root with something like /data

If the quarto file and the resource directory are both at the top level of the project, everything works.

I created a test project that shows this behavior https://github.com/anielsen001/test-quarto-live

I tried to follow the example from the docs here: https://r-wasm.github.io/quarto-live/other/resources.html

There's a working version in https://github.com/anielsen001/test-quarto-live/blob/main/resource.qmd

I have a version is a subdirectory, which I can get to work: https://github.com/anielsen001/test-quarto-live/blob/main/subresource/subres.qmd

So, I don't know if this is a bug per se, but it would be nice for the path to be relative to the project. At the very least, I think this should be a documentation update, and I'm willing to help on the documentation if that seems like the best way to go.

@georgestagg
Copy link
Member

Hi, thanks for your work debugging this and replying with further updated information.

I think your suggestion of supporting paths with a leading slash as relative to the project root is a good idea, particularly if it matches other existing behaviour in Quarto.

In the shorter term I'm happy to accept documentation PRs, we can always revert them once the correct functionality has been implemented.

@georgestagg georgestagg added documentation Improvements or additions to documentation enhancement New feature or request labels Jan 22, 2025
@anielsen001
Copy link
Author

thank you. I will take a look at the documentation when I have a moment and see about making some comments and maybe adding some examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants