Bokeh 0.7.1:动态将图添加到Bokeh-Server生成的现有页面 [英] Bokeh 0.7.1: Dynamically Add Plot to Bokeh-Server Generated Existing Page

查看:120
本文介绍了Bokeh 0.7.1:动态将图添加到Bokeh-Server生成的现有页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用bokeh-server来处理通过tcp进行的数据流传输,以绘制当前使用output_server显示给浏览器的图.我希望能够动态地向当前浏览器页面添加更多图表,因为数据会通过套接字传递.我的麻烦之一是我不完全了解cursession()和curdoc()的工作方式/它们如何不同.

I'm using bokeh-server to handle data streaming via tcp to plots that I currently have displaying to browser using output_server. I'd like to be able to dynamically add more plots to the current browser page, as the data comes through on the socket. Part of my trouble is that I don't fully understand how cursession() and curdoc() work/how they are different.

我当前的代码如下:

 plots = []

 if create_new_plot:
      plots.append(create_new_plot_def())
 if open_new_tab:
      show(plots)
      open_new_tab = False
 else:
      curdoc().add(plots)

运行此命令时,出现一个错误,即列表"对象没有属性引用".为了解决这个问题,看来我不得不循环遍历并分别添加每个图,但这还是行不通的. plots[]包含我想在当前时间显示的所有绘图对象的运行列表.我发现一种解决方法是每次都只使用show(),但是每次都在浏览器中打开一个新标签,这不切实际/不优雅.

When I run this, I get an error that the 'list' object has no attribute 'references.' In order to fix this, it seems that I would have to loop through and add each plot individually, but that also does not work. The plots[] contains a running list of all of the plot objects I would like displayed at current time. One work around that I've found is to just use show() each time, but that opens a new tab in my browser each time, which isn't practical/elegant.

传统上,我使用cursession().add_object()更新绘图上的数据源.在我看来,cursession()处理所有数据后端,而curdoc()控制页面上的实际可视化.这是正确的吗?

Traditionally, I use cursession().add_object() to update the datasource on my plots. It seems to me that cursession() deals with all of the data backend, whereas curdoc() controls the actual visualization on the page. Is this correct?

我是否可以在相同的现有浏览器页面(即文档)上触发全新地块的显示?有人可以简要解释一下如何正确使用cursession()和curdoc()吗?谢谢!

Is there a way for me to trigger the display of a brand new plot, on the same existing browsers page, ie document? Can somebody explain, briefly, how to use cursession() and curdoc() properly? Thanks!

我找到了一个修复程序,但仍然无法解决多个show()调用,这些调用导致打开多个浏览器选项卡.我的代码现在看起来像这样:

I have found a fix, but still can't get around the multiple show() calls, that cause multiple browser tabs to open. My code now looks like this:

if open_tab:
     show(grid_plot)
     open_tab = False
else:
    curdoc().clear()
    curdoc().add(grid_plot)
    show()

推荐答案

我也在io.py中使用push()找到了解决方案.可以使用的新代码段:

I found a solution by using push(), also in io.py. The new code snippet that works:

if open_tab:
     show(grid_plot)
     open_tab = False
else:
     curdoc().clear()
     curdoc().add(grid_plot)
     push()

这样做,将刷新html页面,而不是生成第二个重复的页面(新标签).

In doing so, the html page is refreshed, rather than a second duplicate page being generated (new tab).

查看以下内容: https://groups. google.com/a/continuum.io/d/msg/bokeh/rMDt1sT5Cwk/fkKfS8yeTO8J 了解curdoc()vs cursession()的解释.请注意即将推出的文档.

Check this out: https://groups.google.com/a/continuum.io/d/msg/bokeh/rMDt1sT5Cwk/fkKfS8yeTO8J for an explanation on curdoc() vs cursession(). Look out for documentation coming soon.

这篇关于Bokeh 0.7.1:动态将图添加到Bokeh-Server生成的现有页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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