Unlisted
Edited
Mar 1
Importers
Insert cell
Insert cell
runtime._modules
Insert cell
importNotebook("@tomlarkworthy/exporter", [
{
imported: "exporter",
/* optional */ local: "exporter2"
}
])
Insert cell
Insert cell
exporter2() // this depenancy has come from the scripted import
Insert cell
importNotebook = async (notebook, specifiers = []) => {
runtime;
// We need to eval so the definition contains the literal of the import, so exporter can read the
// source later (in findModuleSource specifically)
// If we are on Observable we use the API otherwise, a short name that hits the lopecode importMap
// const url = isOnObservableCom()
// ? `https://api.observablehq.com/${notebook}.js?v=4&${resolutions_key}`
// : `${notebook}`;
// const fn = eval(
// `async () => runtime.module((await import("${url}")).default)`
// );
// // check it loads
// const result = await fn();

let fn;
for (const url of [
notebook,
`https://api.observablehq.com/${notebook}.js?v=4&${resolutions_key}`
]) {
try {
fn = eval(`async () => runtime.module((await import("${url}")).default)`);
await fn();
break;
} catch {}
}
if (!fn) throw `Can't resolve ${notebook}`;

const module_variable = `module ${notebook}`;

if (!main._scope.has(module_variable)) {
main.define(module_variable, fn);
}

for (let { imported, local = null } of specifiers) {
if (!local) local = imported;
if (!main._scope.has(local)) {
main.define(local, [module_variable, "@variable"], (_, v) =>
v.import(imported, local, _)
);
} else {
main.redefine(local, [module_variable, "@variable"], (_, v) =>
v.import(imported, local, _)
);
}
}

return md`~~~js
importNotebook("${notebook}", ${JSON.stringify(specifiers)})
~~~`;
}
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more