Embed an interactive Bokeh in django views

梦想与她 提交于 2019-12-20 09:03:32

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/41779125/embed-an-interactive-bokeh-in-django-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!