Search code examples
vega-lite

Pass parameters to a vega-lite spec?


I'm looking for an idiomatic way to pass parameters into a vega-lite spec via vegaEmbed(). For example, I'd like to pass the data url, so that instead of my spec containing:

"data": {"url": "filename.json"},

it contained something like:

"data": {"url": parameters["dataURL"]},

At a high level, I want to display visualizations from external applications via a url, something like http://localhost/showViz.html?data=today.json&sort=ascending so it's not just about specifying the data source, I'm looking for a general mechanism to parameterize my specs.

I tried passing something via vegaEmbed's opt argument, but couldn't work-out how to access it from the vega-lite spec (either as usermeta or not). If the opt argument is the preferred way to do something like this, then my question devolves to "how do I reference opt and/or usermeta values from a vega-lite spec?".


Solution

  • No, there is no standard means to parametrize inputs that is built-in to Vega or Vega-Lite.

    There are third-party tools that do something similar to what you have in mind, for example Vega Kibana, which provides a templating syntax for charts.

    If you want to do this using native Vega/Vega-Lite, you can always use Javascript to modify the specification before passing it to the renderer, and/or use the vega-embed patch option to provide a javascript function that will patch the Vega specification (not Vega-Lite specification) before it is rendered.