Parametrized data loaders don't work for me

I must be doing something wrong, something obvious, but I can’t spot the problem. I have the following setup:

  • games/[game].md is pretty trivial, tries to load a JSON: const game = FileAttachment(`./data/games/${observable.params.game}.json`).json();
  • data loader, data/games/[game].json.py should supply the JSON data - it works when I run it manually
  • but, when I open the page, e.g. /games/87, Observable seems never to register the data loader: it’s not triggered, not executed, not mentioned in npm run dev output, and no 87.json file is generated. Page displays “Error: Unable to load file: 87.json” message.

What else can I check? Any hints WRT debugging the problem? Data loaders seem to work in general, I already have some non-parametrized ones, and they work like a charm.

Hi there! Do you mind asking on GitHub instead of the Observable Forum? You can open a discussion in the Q&A section, or file an issue if you’ve found a bug.

We’re trying to consolidate our open-source discussions onto GitHub. Thank you!

Also, please include the version of Framework are you using.

Is the path here correct? This would imply that the data lives in

/games/data/games/[game].json

But your message suggests that the data lives in

/data/games/[game].json

In which case the code should either be

FileAttachment(`../data/games/${observable.params.game}.json`)

or if you prefer an absolute path

FileAttachment(`/data/games/${observable.params.game}.json`)
1 Like

Absolutely, will do - next time, because…

This was it! I knew it would be something as trivial as an incorrect path, and I did play a bit with paths, moving files and directories around, but it never occurred to me it’s actually one level below. Thank you!

I’ll switch to absolute paths, I’m not going to have too many nested directories, it will be much easier to maintain.

4 Likes