我想在Django视图(或模型)中制作交互式绘图。.假设我想使用selection_histogram example.
我认为Bokeh适合我的需求,因为我有Matplot/Seaborn可以重用,而且我不太擅长JavaScript。
对于我来说,遵循这个例子没有问题:how to embed standalone bokeh graphs into django templates。
据我所知,我需要运行bokeh服务器并make some proxy using nginx
如何将交互式Bokeh图嵌入到Django视图中?
我试过这个:
启动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})
现在,它像预期的那样是交互式的。
有没有方法将一些参数传递给bokeh应用程序?
任何帮助都将不胜感激。
当做
最佳答案
在django中使用bokeh不需要运行bokeh服务器。只需将bokeh导入到views.py中即可。
您需要在模板中加载bokeh js和css,并呈现由bokeh创建的组件。它认为this是一个简明的例子。