-
Hi all, I'm working with Observable Framework and trying to build dynamic visualizations that respond to user input. The user inputs are fairly simple—typically filtering data by geographic location (e.g., country) and year. However, the underlying dataset is quite large (5 million+ rows), so performance is a concern. I'm looking for an efficient way to handle this, especially given that I'm new to Observable Framework. I came across parameterized routes and thought they might help. I tried to use them to dynamically load a CSV file based on the route params. Here's what I attempted: const tempdata = await FileAttachment(
`data/sunburst-${observable.params.country}-${observable.params.year}.csv`
).csv({
typed: true,
}); But this gives the error:
From what I understand, FileAttachment() doesn’t support dynamic paths via template strings, which throws off my initial idea. My questions:What’s the best practice for dynamically loading data based on route parameters in Observable Framework? Should I be using a several data loaders to query the various filtered versions of the dataset on-demand? What's the solution there? Are there any recommended patterns or examples for handling large datasets efficiently in the Observable Framework context? Any help or advice would be greatly appreciated! Thanks 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi Avindhya - the way you're doing it makes sense. Route params should be an exception to the static string literal rule, as documented here. Curious if it makes any difference with just a single parameter in the string. Also, do the params show up properly if you log them to the console outside of the file attachment code? If the params are correct, we should probably file a bug. Is there a minimal example you could share so I could reproduce the issue? Instead of outputting to csv, you may want to look into parquet data loaders to handle larger datasets in fewer files. |
Beta Was this translation helpful? Give feedback.
Hi Avindhya - the data loaders run at build time, so it's not possible to pass back user input you get at run time. This is so that dashboards load quickly by not running a new query in response to user input. The way you have it set up with parameterized routes, a user selecting a country and year should take them to a new page, which loads the static file that has already been produced by the data loader at build time.
If you're creating a single-page application, you might want to look into creating a duckDB database client, which would allow you to run SQL queries based on user input: https://observablehq.com/framework/lib/duckdb