How to make vegalite read my topojson file?

There are two different ways in which you can load data: 1) you can create a Path object from the FilePaths.jl package that points to your file and put that into your spec, or 2) you can pass the values themselves.

In the case of 1) you are not loading the values yourself, but you let vega/vega-lite load the data from disc, i.e. you just put a pointer to the file into the figure. In theory this is great, but in practice we have a problem that this doesn’t work for various display front-ends (it doesn’t work in VS Code, ElectronDisplay and the default browser viewer, not sure about Jupyter). It does work if you save such a figure to disc with save.

In the case of 2) you need to load the data yourself into memory in Julia, and then pass the data itself to vega/vega-lite. This should always work.

In the case of 1) we don’t have to worry about different file formats, vega is going to figure it out.

In the case of 2) we need to differentiate a bit between tabular and other data. For tabular data anything that complies with the TableTraits.jl interface can be passed, which is pretty much everything, so that is easy. For non-tabular data, for example a topjson, you should ideally use JSON.jl to read the file content and pass it to VegaLite.jl. The code might look like this:

data={
    values=JSON.parsefile(filename),
    format={
        typ=:topojson,
        feature=:disa_ONT_region
    }
}

Let me know if this works!

1 Like