Dynamic import

Hi all,

First off, I would like to thank you for ObservableHQ, it has been a great resource over the past 4 years, and the engineering behind it is remarkable.

I’m at a bit of loss with an issue I have at the moment.

I have a piece of code that looks like so.

import {exportCSVData as exportCSVData1} 
with {h1 as galaxyHistoryId}
from "@stevenweaver/ngsqc-parser"

h1 is currently an ID that is passed into another notebook. What I would like is iterate over a list of IDs, and assign an array of resulting export variables.

For example

import {exportCSVData as exportCSVData2} 
with {h2 as galaxyHistoryId}
from "@stevenweaver/ngsqc-parser"

import {exportCSVData as exportCSVData3} 
with {h3 as galaxyHistoryId}
from "@stevenweaver/ngsqc-parser"

and so on, but programmatically. Is there any way to make this possible?

Best and thank you,

Thanks Steven!

Yes, it’s possible to do dynamic imports (see this prototype) but I don’t think I recommend it as it’s not really a supported feature. Instead I recommend refactoring the notebook you import as a function and avoiding import-with entirely. So you might say something like this:

import {exportCSVData} from "@stevenweaver/ngsqc-parser"
exportCSVData({galaxyHistoryId: h2})
exportCSVData({galaxyHistoryId: h3})

You’ll have to rewrite your other notebook to be more function-based rather than cell-based, but overall it’ll make it easier to reuse in the standard JavaScript way.

Thank you mbostock.

I was leaning towards that way, but I just wanted to make sure.