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

Technique example: data loader, R to ZIP #1423

Merged
merged 9 commits into from
Jul 15, 2024
Merged

Conversation

allisonhorst
Copy link
Contributor

@allisonhorst allisonhorst commented Jun 3, 2024

Allison Horst and others added 2 commits May 31, 2024 17:23
@allisonhorst allisonhorst requested review from Fil and mbostock June 3, 2024 13:51
@Fil
Copy link
Contributor

Fil commented Jun 6, 2024

The error in build comes from using this two-step strategy to load the file:

const modelZip = FileAttachment("data/penguin-mlr.zip").zip();
const modelEstimates = modelZip.file("estimates.csv").csv({typed: true});

Framework is not smart enough here to know that it will need d3-dsv, and does not include it by default. (This is arguably a bug in Framework, in the sense that it builds an incomplete stdlib—maybe we should preventively build all the methods that stdlib might need?)

The most natural way to solve this for the example page is to rewrite that paragraph as:

-You can then access individual files (estimates.csv, or predictions.csv) from the ZIP archive:
+Or access individual files (`estimates.csv`, or `predictions.csv`):

 ```js echo
-const modelEstimates = modelZip.file("estimates.csv").csv({typed: true});
+const modelEstimates = FileAttachment("data/penguin-mlr/estimates.csv").csv({typed: true});
 ```

which I think conveys the intended use of zip files better.

Another way to fix is to make an explicit import of d3-dsv, even an empty one:

```js
import {} from "npm:d3-dsv"
```

but it does feel weird.

@mbostock
Copy link
Member

mbostock commented Jun 6, 2024

You can shorten that to

import "npm:d3-dsv";

but you should use the automatic unpacking of the .csv and not load the .zip in the client anyway. You should only load a .zip in the client if you want to do something “dynamic” with the contents (in which case you can’t benefit from static analysis).

@allisonhorst
Copy link
Contributor Author

@Fil @mbostock thank you! I've updated this to only load in the individual files (no longer loading the ZIP in the client).

@allisonhorst allisonhorst marked this pull request as ready for review June 15, 2024 03:31
Copy link
Contributor

@Fil Fil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a bit harsh to give a model without a chart, but that's up to you :)

I added two nits

examples/loader-r-to-zip/src/data/penguin-mlr.zip.R Outdated Show resolved Hide resolved
examples/loader-r-to-zip/src/index.md Outdated Show resolved Hide resolved
@allisonhorst allisonhorst merged commit ef19d93 into main Jul 15, 2024
4 checks passed
@allisonhorst allisonhorst deleted the allison/r-zip-loader branch July 15, 2024 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants