Calmcode - altair: json

Generate Altair Charts as Json or HTML in Python.

1 2 3 4 5 6 7 8 9

Export Altair to HTML/Json

You can call .to_json and .to_html on any chart that you've defined to get the json or html out.

days = ['Mon', 'Tues', 'Wed', 'Thurs', 'Fri', 'Sat', 'Sun']

p1 = (alt.Chart(plot_df)
  .encode(x='date', y='births', color=alt.Color('wday', sort=days))
  .properties(width=125, height=125)


You can also save the json file to disk if you liked to be served as a file by a server later.

import pathlib



Below you'll see an example of the hosted chart.

We're using a little trick to help us host this via the justcharts project. Here's the code that we used:

<script src="[email protected]"></script>
<script src="[email protected]"></script>
<script src="[email protected]"></script>
<script src=""></script>

<vegachart schema-url="chart-schema.json"></vegachart>

If this sounds interesting, you can learn more about it on the justcharts announcement page.