My question: variables can be imported from one notebook to another (awesome), but is there a way to access a notebook’s variables from outside Observable? I’d like to use a notebook to programmatically assemble some data, and then access that data from elsewhere. Thanks…
At the moment, there isn’t a convenient way to load data directly from an Observable notebook. But we’re working on it! A feature for downloading a notebook to run standalone, and/or embedding a notebook on your website — including being able to access the live values of cells — is in the works.
In the meantime, I’d recommend using the DOM.download
function in the standard library to export your final, processed data as a JSON file that you can then use anywhere you please.
See: https://beta.observablehq.com/@mbostock/standard-library and https://beta.observablehq.com/@mbostock/saving-svg for some DOM.download
examples.
Saving SVG / Mike Bostock | Observable fails on my computer with Firefox:
“Content Security Policy: Les paramètres de la page ont empêché le chargement d’une ressource à blob:null/91cfa61f-27f3-a146-8f3e-348ed4d32958 (« frame-src https://static.observableusercontent.com »).”
(It works on Chrome.)
OK, thanks! Looking forward to future developments.
@Fil: Thanks for the bug report! I’ve added blob:
and data:
frame sources to our Content Security Policy — so you should be able to use DOM.download
from Firefox without problems now.
Let us know if you run into anything else!
We’ve launched embeddable notebooks this morning, which means that you can now programmatically access a notebook’s variables from anywhere you’d like.
The full details are available in that link, but in short:
Runtime.load(notebook, (variable) => {
if (variable.name === "data") {
return {
fulfilled: (value) => myApp.setData(value)
};
}
});
Enjoy!
Excellent, thanks for the update—can’t wait to try it out!