Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embed an interactive Bokeh in django views

I want to make interactive plot in django views (or model ?). Let's say I want to use selection_histogram example. I think Bokeh fit my needs because, I have matplot/seaborn that I can reuse and I'm not pretty good at javascript.

There was no problem for me to follow this example : how to embed standalone bokeh graphs into django templates.

As I understand, I need to run a bokeh server and make some proxy using nginx

How can I embed a interactive bokeh plot into a django view ?

I tried this :

Launch bokeh server

bokeh serve --allow-websocket-origin=127.0.0.1:8001 selection_histogram.py

Update my view in views.py

def simple_chart(request):

    script = autoload_server(model=None,
                             app_path="/selection_histogram",
                             url="http://localhost:5006/")


    return render(request, "simple_chart.html", {"the_script": script})

Now, it is interactive as expected.

Is there a way to pass some arguments to bokeh application ?

Any helps will be appreciated. Regards

like image 238
Thomas PEDOT Avatar asked Jan 21 '17 12:01

Thomas PEDOT


1 Answers

You don't need to run a Bokeh server to use Bokeh in DJANGO. You can just import Bokeh into you views.py.

You need to load the Bokeh js and css in your template, and render the components created by Bokeh. It think this is a concise example.

like image 185
DA-- Avatar answered Oct 11 '22 14:10

DA--