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

Parameterized data loaders & pages #245

Open
mbostock opened this issue Nov 27, 2023 · 5 comments · May be fixed by #1523
Open

Parameterized data loaders & pages #245

mbostock opened this issue Nov 27, 2023 · 5 comments · May be fixed by #1523
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

mbostock commented Nov 27, 2023

What if we supported dynamic routes for data loaders, e.g. customer/@[login].csv.ts would match customer/@mbostock.csv, and would pass --login=mbostock as a command-line argument (parameter) to the data loader. This way you could use the same data loader to generate multiple files (though all files would need to be statically referenced in order to be built).

@mbostock mbostock added the enhancement New feature or request label Nov 27, 2023
@mbostock mbostock added this to the Future milestone Nov 27, 2023
@mbostock mbostock changed the title Parameterized data loaders Dec 11, 2023
@mbostock
Copy link
Member Author

This would also apply to data loaders requested from parameterized pages. For example you could have a route @[login]/index.md, and adjacent @[login]/profile.csv.ts; then --login=mbostock would get passed to the data loader if you access @mbostock/ and @[login]/index.md references FileAttachment("profile.csv.ts").

The challenge is that we’ll need some way to enumerate all the possible values of the [login] parameter… 🤔

@Fil
Copy link
Contributor

Fil commented Dec 11, 2023

I can see how we could generate it from all links found in the static pages (since it would be nice to test links anyway, per #363), but also how it could be in the config (as an array), or in front-matter, like:

--- 
login:
 - one
 - two
 - three
---
@tel
Copy link

tel commented Feb 16, 2024

I'm highly interested in this. As an example, I have some code that does (somewhat intensive) simulations in Rust. I'd love to be able to parameterize those simulations in the call to the data loader and have the data be cached.

Ideally, this means that I can write the data loader file (sim.parquet.rs) and pass it arguments. Each call to the loader ought to be cached so that my workflow only involves rerunning the simulation when I change either the sim.parquet.rs file or its parameters. That way I can iterate on data exploration much more rapidly than I could without the caching.

Without parameterized data loaders, I can achieve something similar by making many different *.parquet.rs files each calling the underlying simulation code with different parameters. I haven't tested this yet, but I imagine this will work poorly with the caching system as if I make a change to the underlying simulator (a common event) I would need to manually invalidate all of those data loader files so that they have a chance to be re-run with the new dependency.

I can also imagine solving this with a feature such as #145. That might be more flexible, though I haven't thought it through and it'd also be annoying to have to constantly write out the Cargo.toml preamble.

@Fil
Copy link
Contributor

Fil commented Mar 23, 2024

We could also require that the values be enumerated in the config file (for build, not for preview where it would be uncontrolled—leaving the developer free to explore).

@mbostock mbostock removed this from the Future milestone Mar 24, 2024
@cedricr
Copy link

cedricr commented Jun 22, 2024

We could also require that the values be enumerated in the config file (for build, not for preview where it would be uncontrolled—leaving the developer free to explore

Sveltekit solves that by crawling + optional configuration when prerendering or a static target is requested :
https://kit.svelte.dev/docs/page-options#entries

@observablehq observablehq deleted a comment from ermhawi Jun 25, 2024
@mbostock mbostock linked a pull request Jul 17, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
4 participants