[Fixed]-Bokeh Chart to image from django view


I’d recommend using the bokeh.embed module:


from bokeh.embed import components
script, div = components(pt)

Then you just have to insert the script and div into your html template.

Sarah Bird also gave a good talk on embedding Bokeh plots in Django apps at Pycon: (https://us.pycon.org/2015/schedule/presentation/369/)


Thank you. That worked!

in views.py

import pandas as pd
from bokeh.charts import Histogram

def stock_chart(request):
    histo_xyvalues = pd.DataFrame(dict(normal=[1, 2, 3, 1], lognormal=[5, 4, 4, 1]))
    hm = Histogram(histo_xyvalues, bins=5, title='Histogram' , width=300, height=300)
    script, div = components(hm)
    return HttpResponse(script+div)

in urls.py
    url(r'^stock_chart/$', views.stock_chart, name="stock_chart"),

a call from javascript/jQuery is,
$.get('/stock_chart/', function(data){


Leave a comment