Skip to content

Commit b1f187e

Browse files
committed
more about sharing plots; closes #33, closes #34
1 parent 2396535 commit b1f187e

File tree

1 file changed

+48
-1
lines changed

1 file changed

+48
-1
lines changed

content/sharing.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Sharing notebooks
1+
# Sharing plots and notebooks
22

33
:::{objectives}
44
- Know about good practices for notebooks to make them reusable
@@ -44,6 +44,53 @@ This is not only useful for people who will try to rerun this in future, it is a
4444
understood by some tools (e.g. [Binder](https://mybinder.org/)) which we will see later.
4545

4646

47+
## Different ways to share a Vega-Altair plot
48+
49+
- Save it in SVG format (vector graphics, "maximum resolution")
50+
- Save it in PNG format (raster graphics)
51+
- Share it as notebook (more about it below)
52+
- Save it a web page with `chart.save("chart.html")` and share the HTML file
53+
- You can also get a shareable URL to a chart ([example](https://altair-viz.github.io/user_guide/saving_charts.html#sharable-url))
54+
- With **sensitive data**, you need to be careful with sharing (see next section)
55+
56+
57+
## Vega-Altair and notebooks containing sensitive data
58+
59+
If you plot **sensitive data** in a notebook with Vega-Altair,
60+
you need to be careful.
61+
62+
The author of Vega-Altair provided a good summary in this [GitHub comment](https://github.com/vega/altair/issues/1250#issuecomment-444269060):
63+
64+
> "Standard Altair rendering requires the entire dataset to be accessible to
65+
> the viewer's browser: this is a fundamental design decision in
66+
> Vega/Vega-Lite, in which a chart is equivalent to a dataset plus a
67+
> specification of how to render it. In general, you should assume that the
68+
> entire contents of any dataframe you pass to the alt.Chart() object will be
69+
> saved in the notebook and be inspectable by the viewer."
70+
71+
> "One way to get around this would be to render the chart server-side, export
72+
> a PNG, and display this png instead of the live chart. Incidentally, in the
73+
> Jupyter notebook you can do this by running:"
74+
75+
> `alt.renderers.enable('png')`
76+
77+
> "This sets up Altair such that charts will be
78+
> rendered to PNG within the kernel, and only that PNG rendering will be
79+
> embedded in the notebook. Note this requires some extra dependencies,
80+
> described [here](https://altair-viz.github.io/user_guide/saving_charts.html#png-and-svg-format)."
81+
82+
> "But even here, I wouldn't call your data "private" (for example, if you
83+
> save a scatter plot to PNG, a user can straightforwardly read the data
84+
> values off the chart!) So this makes me think you're actually doing some
85+
> sort of aggregation of your data before plotting (e.g. showing a
86+
> histogram). If this is the case, I would suggest doing those aggregations
87+
> outside of Altair using e.g. pandas, and then passing the aggregated
88+
> dataset to the chart. Then you get the normal interactive display of the
89+
> Altair chart, and your data is just as private as it would have been in the
90+
> equivalent static rendering – the user can only see the aggregated values
91+
> you supplied to the chart."
92+
93+
4794
## Different ways to share a notebook
4895

4996
We need to learn how to share notebooks. At the minimum we need

0 commit comments

Comments
 (0)