18

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

Community
  • 1
  • 1
Thomas PEDOT
  • 943
  • 1
  • 9
  • 18
  • Just to clarify your question, do you wish to render widgets or form inputs in your django template then have them communicate with the bokeh server (e.g. to change your plot's scale or data values)? If so, this is similar to a problem I'm having, and I think the solution lies in bokeh.js, but I've yet to figure out a good pattern for this. – Brad Montgomery Mar 08 '17 at 16:27
  • 1
    Hello, I saw your activity on Gitter. I succeed to render a bokeh widget with django dataset. My problem was how to make both servers talk to each other. – Thomas PEDOT Mar 10 '17 at 08:50
  • Can you explain what you mean by interactive: 1. The tools should work (zoom, pan, hover etc), or 2. The data and the plots should update even without a new page request – renzop Sep 13 '17 at 08:28
  • My original question was client server interactivity like in the example. Everytime the user select data in the graph some calculations are made on server side and updated result is called back to the client. – Thomas PEDOT Sep 14 '17 at 08:59
  • can you post your simplified code on how you embedded Bokeh server in Django view (so that you can have callbacks on Bokeh widgets)? – Hossein Kalbasi Mar 20 '19 at 16:22

1 Answers1

8

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.

DA--
  • 723
  • 1
  • 8
  • 20
  • 1
    Thanks for your answer. The example is the same has I mention in my question. This simple example is "static". I can use matplolib likely to do that. I will edit my question to be more specific. – Thomas PEDOT Jan 21 '17 at 17:22
  • Ah OK, then I don't understand which kind of interactiveness requires the bokeh server :) – DA-- Jan 21 '17 at 17:27