[Fixed]-Bokeh Chart to image from django view

1👍

I’d recommend using the bokeh.embed module:

http://docs.bokeh.org/en/latest/docs/user_guide/embed.html#components

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/)

0👍

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){
     $('#chart_area').append(data);
});


...
👤shaz

Leave a comment