2

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.

My current code looks like this:

 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)

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.

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?

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!


Edit: 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()
Amy D
  • 571
  • 2
  • 7
  • 16

1 Answers1

2

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()

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

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.

Amy D
  • 571
  • 2
  • 7
  • 16