1

When using JS to render a vega-lite chart that was originally built in Python (using altair), the default is to allow a variety of options on the chart itself: save as image, view source, and Open in Vega Editor.

Using this method, we can modify those options by adjusting the vega-embed "actions" option:

"actions": {"editor": false}

Eg:

var spec = JSON.parse({{ graph_json|tojson }})
var opt = {   /* Options for the embedding */
  "renderer": "canvas",
  "actions": {
    "export": true,    /* "Save as PNG|SVG" */
    "source": true,    /* "View Source" */
    "compiled": true,  /* "View Vega Source" */
    "editor": false    /* Do not allow export to https://vega.github.io/editor */
  }
};
vegaEmbed("#vis", spec, opt);

However, when using altair in a colab / Jupyter Notebook, we don't have access to that JS. Is there a way to modify those options using altair directly?

I was thinking there might be a renderer option, but I haven't been able to find anything. Perhaps there's a way to customize the colab renderer?


Alternatively, how about setting editorUrl?

But why do I want to do this?

TL;DR: Data exfiltration risk.

Disabling those "Show Source" and "Editor" buttons is one part of data exfil protection. Using a self-hosted editor instead of the default github one is another acceptable method.

dthor
  • 1,749
  • 1
  • 18
  • 45

1 Answers1

2

Altair 2.3.0 (2018-12-07) added the mostly-undocumented set_embed_options() method to renderers, which means you can send any args to vega-embed.

Usage:

df = pd.DataFrame({"x": [1, 2, 3], "y": [1, 2, 3]})
alt.renderers.set_embed_options(actions={"editor": False})
alt.Chart(df).mark_bar().encode(...)
alt.renderers.set_embed_options(editorUrl="http://localhost:8080")
dthor
  • 1,749
  • 1
  • 18
  • 45