Public
Edited
Mar 26, 2023
Insert cell
Insert cell
Insert cell
Insert cell
/**
* @param {object} config The "template" config containing URLs with "{{ base_url }}".
* @param {function} handleUrl Function that takes in a (potentially template) URL string and returns a filled-in URL string.
* @returns {object} The config with handleUrl having been called to process every URL.
*/
fillUrls = (config, handleUrl, handleRequestInit) => {
return {
...config,
datasets: config.datasets.map((datasetDef) => {
return {
...datasetDef,
files: datasetDef.files.map((fileDef) => {
return {
...fileDef,
...(fileDef.url ? ({
url: handleUrl(fileDef.url, fileDef.fileType.includes("zarr"))
}) : {}),
...(fileDef.fileType.includes("zarr") ? ({
requestInit: handleRequestInit()
}) : {}),
...(fileDef.options?.images ? ({
options: {
...fileDef.options,
images: fileDef.options.images.map((imageDef) => {
return {
...imageDef,
url: handleUrl(imageDef.url, false),
...(imageDef.metadata?.omeTiffOffsetsUrl ? ({
metadata: {
...imageDef.metadata,
omeTiffOffsetsUrl: handleUrl(imageDef.metadata.omeTiffOffsetsUrl, false),
},
}) : {}),
};
}),
},
}) : {}),
};
}),
};
}),
};
}
Insert cell
myRequestInitHandler = () => {
const token = 'example_token';
return {
headers: {
Authorization: `Bearer ${token}`
}
}
}
Insert cell
myUrlHandler = (url, isZarr) => {
return `${url.replace("{{ base_url }}", "https://portal.test.hubmapconsortium.org/SOMETHING")}${isZarr ? '' : '?token=12345'}`;
};
Insert cell
fillUrls(visiumConfig, myUrlHandler, myRequestInitHandler)
Insert cell
fillUrls(imsConfig, myUrlHandler, myRequestInitHandler)
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