Skip to content

Instantly share code, notes, and snippets.

@taddeimania
Last active August 29, 2015 14:25
Show Gist options
  • Save taddeimania/f3ba17b7bc8889bb0a0f to your computer and use it in GitHub Desktop.
Save taddeimania/f3ba17b7bc8889bb0a0f to your computer and use it in GitHub Desktop.
Bokeh Graph to context object in Template
from bokeh.embed import components
from bokeh.plotting import figure
from django.shortcuts import render_to_response
def graph_view(request):
x_data, y_data = ([1, 2, 3, 4], [10, 1, 5, 3])
plot = figure()
plot.line(x_data, y_data)
script, div = components(plot)
return render_to_response("base.html", {"bokeh_script": script, "bokeh_graph": div})
# base.html
"""
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<link href="http://cdn.pydata.org/bokeh/release/bokeh-0.9.1.min.css"
rel="stylesheet" type="text/css">
<title></title>
</head>
<body>
<script src="http://cdn.pydata.org/bokeh/release/bokeh-0.9.1.min.js"></script>
{% autoescape off %}
{{ bokeh_graph }}
{{ bokeh_script }}
{% endautoescape %}
</body>
</html>
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment