Created
August 3, 2018 12:58
-
-
Save Hugovdberg/96f0645ad13717d282026222eb5c32bf to your computer and use it in GitHub Desktop.
nbconvert template with support for (interactive) altair plots
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends 'full.tpl' %} | |
{% block header %} | |
<script src="https://cdn.jsdelivr.net/npm/vega@3"></script> | |
<script src="https://cdn.jsdelivr.net/npm/vega-lite@2"></script> | |
<script src="https://cdn.jsdelivr.net/npm/vega-embed@3"></script> | |
{{super()}} | |
{% endblock header %} | |
{%- block data_priority scoped -%} | |
{% if 'application/vnd.vegalite.v2+json' in output.data %} | |
<div id="vis{{cell['execution_count']}}"></div> | |
<script type="text/javascript"> | |
var spec = {{ output.data['application/vnd.vegalite.v2+json'] }}; | |
var opt = {"renderer": "canvas", "actions": false}; | |
vegaEmbed("#vis{{cell['execution_count']}}", spec, opt); | |
</script> | |
{% else %} | |
{{super()}} | |
{% endif %} | |
{%- endblock data_priority -%} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this. Your gist does not work on all visualization types. Maps created in Altair were not included with 'application/vnd.vegalite.v2+json', because it was a different MIME type. I extended your code to all listed here and it worked.