I’m trying to set up a notebook automatically from data stored in my web app. I can attach a file programatically but haven’t been able to update a cell. What I’ve done so far is generate the code and copy it in the cell and that works.
TIA
Hi Gabriel. Sounds like a cool use case!
Unfortunately I don’t have any immediate recommendations on how to edit notebooks programmatically; in general we discourage it because a lot of our security mechanisms rely on static analysis. If we allow programmatic editing of notebooks (at least from within the notebook itself), then static analysis would not provide that extra layer of protection. We made an exception for programmatic file attachments, but that’s only allowed for data and not for code, so we feel it’s worth the trade-off.
But perhaps you don’t need meta programming per se… it sounds like you want more of a dynamic template, where you can link to a page on Observable with some dynamically specified content to seed a notebook? We’ve toyed with this idea in the past, and we could support this as long as the code runs on an anonymous domain without any personal privileges (such as access to private data). You could then fork the notebook into your workspace if you want to grant the code access to data (after reviewing the code, hopefully).
Alternatively, you can write parameterized notebooks if you just need a limited about of dynamic, linkable behavior (and this is the safest route):
https://observablehq.com/@mbostock/parameterized-notebooks?foo=hello