Last active
August 29, 2015 14:25
-
-
Save taddeimania/f3ba17b7bc8889bb0a0f to your computer and use it in GitHub Desktop.
Bokeh Graph to context object in Template
This file contains hidden or 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
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