Can data loaders be dynamically invoked?

Hi,

We are building an observable dashboard where we want to display several plots and statistics for various items. The data source, querying, and processing can differ significantly for each item. Therefore, we need to write a data loader for each one. However, the output of each data loader must follow a consistent structure across all items, so that the same visualizations (a few plots and summary statistic boxes) can be reused.

To display the data, we could hard-code each data loader and use reusable components for the visualizations:

const item1 = FileAttachment("item1.csv").csv({typed: true});
const item2 = FileAttachment("item2.csv").csv({typed: true});

However, it seems it would be easier to maintain if we could dynamically load all available data loaders. This way, when adding a new item, we wouldn’t need to modify the presentation code—just write the new data loader, and it would automatically work.

Is this kind of approach possible? Are there any examples of similar implementations? (We couldn’t find any, but …)

Have you tried parameterized routes? This would allow you to create all the data loaders with only one script. Then you can use a page loader to create the page that reads them all.

Thx!, I haven’t tried that yet, but it sounds like a good idea and perhaps the way to go for us. Many thanks.