在Django视图中嵌入交互式Bokeh [英] Embed an interactive Bokeh in django views

查看:306
本文介绍了在Django视图中嵌入交互式Bokeh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在django视图(或模型?)中进行交互式绘图.假设我要使用 selection_histogram示例. 我认为Bokeh符合我的需求,因为我可以重复使用Matplot/seaborn,而且我不太擅长javascript.

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.

据我了解,我需要运行bokeh服务器和使用Nginx做一些代理

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

如何将交互式散景图嵌入到django视图中?

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

我尝试过这个:

启动bokeh服务器

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

在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.

是否可以将一些参数传递给bokeh应用程序?

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

任何帮助将不胜感激. 问候

Any helps will be appreciated. Regards

推荐答案

您无需运行Bokeh服务器即可在DJANGO中使用Bokeh.您只需将Bokeh导入您的views.py.

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

您需要在模板中加载Bokeh js和CSS,并渲染由Bokeh创建的组件.它认为是一个简洁的示例.

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.

这篇关于在Django视图中嵌入交互式Bokeh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆