run javascript on altair plot clicks

Viewed 670

I can generate altair plots consisting of multiple linked subplots, as can be seen in the famous car data visualization: https://altair-viz.github.io/gallery/selection_histogram.html

Clicks/Selections in one subplot can have an effect on the other subplot(s), mainly via filtering of the data.

However, I do not have a plot on its own, but it is embedded in a bigger web portal (think car dealership page). So my portal is driven by Flask serving pages embedding the altair plots. An example for this can be seen here: https://github.com/lemoncyb/flasked-altair

Functionally, I want to click on one car in the plot and then show some information about this car outside the scope of the plot (e.g. navigate to another page in the portal).

Technically, I want to run custom Javascript code upon clicks/selections.

How is this possible? How does one build bigger sites/applications around an altair plot that require interactions between the plot and the rest of the site?

1 Answers

This cannot be done via Altair itself, but Altair renders its plots via Vega-Lite, which itself is compiled down to Vega. Vega's View API provides a Javascript API for handling events and callbacks in the way you're asking about. You can read more in Vega's Event Handling documentation.

Related