在Django中嵌入具有多个根的Bokeh服务器

时间:2018-10-17 18:43:36

标签: django bokeh

我有一个具有多个根的bokeh应用程序。在bokeh模板内部,我使用

{{embed(roots.plot1)}}
{{embed(roots.plot2)}}
# etc

加载图。这很好。现在,我想将绘图加载到要从Django应用程序提供的网页中。由于我的绘图是使用Holoviews生成的,因此Bokeh服务器至关重要。

散景文档https://github.com/bokeh/bokeh/tree/master/examples提供了有关如何从Bokeh服务器自动加载所有图的示例,还提供了有关如何使用components()嵌入多个静态图的示例,但似乎没有一个涵盖此用例。

这是我尝试过的:

# The following function is a function-based Django view
def django_view(request):

    bokeh_url = 'http://localhost:5006/experiment'
    roots = {root.name: root for root in session.document.roots}

    with pull_session(url=bokeh_url) as session:

        # I was hoping that these will generate separate autoload scripts for each model.
        # Unfortunately they each embed all the models.
        script1 = server_session(session_id=session.id, url=bokeh_url, model=roots['plot1'])
        script2 = server_session(session_id=session.id, url=bokeh_url, model=roots['plot2'])

    return render(request, "template.html", {"script1": script1, "script2: script2})

template.html的摘录:

{{ script1 | safe }}
{{ script2 | safe }}

结果是每个脚本标签将所有图加载到彼此之上。如何在需要的位置将每个图完全嵌入一次?我应该怎么做?

0 个答案:

没有答案