Bokeh 0.7.1: Dynamically Add Plot to Bokeh-Server Generated Existing Page

(Apologies on the cross-post with SO. Searched for a solution but was still unable to resolve the issue)

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

Found a solution, using push() instead of show() the second time.

···

On Monday, March 2, 2015 at 5:03:00 PM UTC-5, [email protected] wrote:

(Apologies on the cross-post with SO. Searched for a solution but was still unable to resolve the issue)

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

Hi ading,

Updating the Users Guide with some information about these things is on my very short list to-do this week. We have done some cleanup/refactoring around this part of Bokeh that should make things easier to explain and understand and to use, so it is a good time to do that. But in brief:

A *session* encapsulates a connection to a Bokeh-server. When you show() or push(), the value of cursession() lets those functions know what server to store data on.

A *document* is really a namespace for sharing objects. It is a collection of Bokeh objects that may refer to one another. Consider two plots that share a range in order to have linked panning. There would be a Document that contains both plots, and the shared range. Plots in different Documents have no way of "sharing" anything. A Document is really just a dictionary that maps unique IDs to Bokeh models. In order to facilitate this sharing, things like output_server() will create a "current" document for you, and this is the value of curdoc(). Documents are used in both static plots and bokeh server plots, it is an orthogonal concept to session.

Let me know if that clears up some of the concepts.

Thanks,

Bryan

···

On Mar 3, 2015, at 9:12 AM, [email protected] wrote:

Found a solution, using push() instead of show() the second time.

On Monday, March 2, 2015 at 5:03:00 PM UTC-5, [email protected] wrote:
(Apologies on the cross-post with SO. Searched for a solution but was still unable to resolve the issue)

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

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2f30f401-fcfb-4f0f-851e-c50f2e3ec4f4%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Bryan,

Thanks, this helps a lot. I had a vague idea about the two concepts, but your explanation really helps to clear up exactly what is going on.

Best,

Amy

···

On Tuesday, March 3, 2015 at 10:23:33 AM UTC-5, Bryan Van de ven wrote:

Hi ading,

Updating the Users Guide with some information about these things is on my very short list to-do this week. We have done some cleanup/refactoring around this part of Bokeh that should make things easier to explain and understand and to use, so it is a good time to do that. But in brief:

A session encapsulates a connection to a Bokeh-server. When you show() or push(), the value of cursession() lets those functions know what server to store data on.

A document is really a namespace for sharing objects. It is a collection of Bokeh objects that may refer to one another. Consider two plots that share a range in order to have linked panning. There would be a Document that contains both plots, and the shared range. Plots in different Documents have no way of “sharing” anything. A Document is really just a dictionary that maps unique IDs to Bokeh models. In order to facilitate this sharing, things like output_server() will create a “current” document for you, and this is the value of curdoc(). Documents are used in both static plots and bokeh server plots, it is an orthogonal concept to session.

Let me know if that clears up some of the concepts.

Thanks,

Bryan

On Mar 3, 2015, at 9:12 AM, [email protected] wrote:

Found a solution, using push() instead of show() the second time.

On Monday, March 2, 2015 at 5:03:00 PM UTC-5, [email protected] wrote:

(Apologies on the cross-post with SO. Searched for a solution but was still unable to resolve the issue)

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

()


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2f30f401-fcfb-4f0f-851e-c50f2e3ec4f4%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi all -

I think this is related (apologies if I’m off). I’m only just starting to dabble with bokeh-server and I’ve gone through the docs and I’m not finding anything for my specific use. In short, I’ve got a job that runs off of cron on a daily basis and outputs to my localhost with output_server.

So I’ve got output_server(‘foo’)

and then I’ve got ts1 and ts2, which are each a bokeh.chartsTimeSeries object

Once I’ve created them the first time, I just show(vplot(ts1, ts2)). However, I don’t want to create a new browser or browser tab every time this happens - I just want to update the doc on the server with the latest.

I’ve tried using save and push in lieu of show, but there’s something I’m missing. Any help and points to documentation would be most appreciated.

Best,

Jerrod

···

On Tuesday, March 3, 2015 at 7:28:24 AM UTC-8, [email protected] wrote:

Hi Bryan,

Thanks, this helps a lot. I had a vague idea about the two concepts, but your explanation really helps to clear up exactly what is going on.

Best,

Amy

On Tuesday, March 3, 2015 at 10:23:33 AM UTC-5, Bryan Van de ven wrote:

Hi ading,

Updating the Users Guide with some information about these things is on my very short list to-do this week. We have done some cleanup/refactoring around this part of Bokeh that should make things easier to explain and understand and to use, so it is a good time to do that. But in brief:

A session encapsulates a connection to a Bokeh-server. When you show() or push(), the value of cursession() lets those functions know what server to store data on.

A document is really a namespace for sharing objects. It is a collection of Bokeh objects that may refer to one another. Consider two plots that share a range in order to have linked panning. There would be a Document that contains both plots, and the shared range. Plots in different Documents have no way of “sharing” anything. A Document is really just a dictionary that maps unique IDs to Bokeh models. In order to facilitate this sharing, things like output_server() will create a “current” document for you, and this is the value of curdoc(). Documents are used in both static plots and bokeh server plots, it is an orthogonal concept to session.

Let me know if that clears up some of the concepts.

Thanks,

Bryan

On Mar 3, 2015, at 9:12 AM, [email protected] wrote:

Found a solution, using push() instead of show() the second time.

On Monday, March 2, 2015 at 5:03:00 PM UTC-5, [email protected] wrote:

(Apologies on the cross-post with SO. Searched for a solution but was still unable to resolve the issue)

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

()


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2f30f401-fcfb-4f0f-851e-c50f2e3ec4f4%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Here is what I have, hope it helps: My plots are all figures, with a collection of lines. For example,

plot1 = figure(title = ‘’, …)

plot1.line(x, y, …)

When creating plot1, I also save renderers[header].extend(plot.select(dict(type = GlyphRenderer))), where renderers is a list I keep, and header is like ‘plot1’

I initially show(plot1). To update the plots, I have a method like this:

def update_plots(header, df, renderers):

ds =

for i in range(0, len(renderers[header])):

r = renderers[header][i]

print r.name

r.data_source.data[‘x’] = df[‘x’]

r.data_source.data[‘y’] = df[‘y’]

ds.append(r.data_source)

cursession().store_objects(*ds)

This might be a bit of a round about way of going about it, now that I look back on it. In essence, what you are doing, is updating the data source for each plot, without actually re-showing the plots.

···

On Tue, Apr 21, 2015 at 11:52 AM, [email protected] wrote:

Hi all -

I think this is related (apologies if I’m off). I’m only just starting to dabble with bokeh-server and I’ve gone through the docs and I’m not finding anything for my specific use. In short, I’ve got a job that runs off of cron on a daily basis and outputs to my localhost with output_server.

So I’ve got output_server(‘foo’)

and then I’ve got ts1 and ts2, which are each a bokeh.chartsTimeSeries object

Once I’ve created them the first time, I just show(vplot(ts1, ts2)). However, I don’t want to create a new browser or browser tab every time this happens - I just want to update the doc on the server with the latest.

I’ve tried using save and push in lieu of show, but there’s something I’m missing. Any help and points to documentation would be most appreciated.

Best,

Jerrod

On Tuesday, March 3, 2015 at 7:28:24 AM UTC-8, [email protected] wrote:

Hi Bryan,

Thanks, this helps a lot. I had a vague idea about the two concepts, but your explanation really helps to clear up exactly what is going on.

Best,

Amy

On Tuesday, March 3, 2015 at 10:23:33 AM UTC-5, Bryan Van de ven wrote:

Hi ading,

Updating the Users Guide with some information about these things is on my very short list to-do this week. We have done some cleanup/refactoring around this part of Bokeh that should make things easier to explain and understand and to use, so it is a good time to do that. But in brief:

A session encapsulates a connection to a Bokeh-server. When you show() or push(), the value of cursession() lets those functions know what server to store data on.

A document is really a namespace for sharing objects. It is a collection of Bokeh objects that may refer to one another. Consider two plots that share a range in order to have linked panning. There would be a Document that contains both plots, and the shared range. Plots in different Documents have no way of “sharing” anything. A Document is really just a dictionary that maps unique IDs to Bokeh models. In order to facilitate this sharing, things like output_server() will create a “current” document for you, and this is the value of curdoc(). Documents are used in both static plots and bokeh server plots, it is an orthogonal concept to session.

Let me know if that clears up some of the concepts.

Thanks,

Bryan

On Mar 3, 2015, at 9:12 AM, [email protected] wrote:

Found a solution, using push() instead of show() the second time.

On Monday, March 2, 2015 at 5:03:00 PM UTC-5, [email protected] wrote:

(Apologies on the cross-post with SO. Searched for a solution but was still unable to resolve the issue)

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

()


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2f30f401-fcfb-4f0f-851e-c50f2e3ec4f4%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

*cursession().store_objects(*ds) is outside of the for loop.

···

On Tuesday, April 21, 2015 at 3:13:16 PM UTC-4, Amy Ding wrote:

Here is what I have, hope it helps: My plots are all figures, with a collection of lines. For example,

plot1 = figure(title = ‘’, …)

plot1.line(x, y, …)

When creating plot1, I also save renderers[header].extend(plot.select(dict(type = GlyphRenderer))), where renderers is a list I keep, and header is like ‘plot1’

I initially show(plot1). To update the plots, I have a method like this:

def update_plots(header, df, renderers):

ds =

for i in range(0, len(renderers[header])):

r = renderers[header][i]

print r.name

r.data_source.data[‘x’] = df[‘x’]

r.data_source.data[‘y’] = df[‘y’]

ds.append(r.data_source)

cursession().store_objects(*ds)

This might be a bit of a round about way of going about it, now that I look back on it. In essence, what you are doing, is updating the data source for each plot, without actually re-showing the plots.

On Tue, Apr 21, 2015 at 11:52 AM, [email protected] wrote:

Hi all -

I think this is related (apologies if I’m off). I’m only just starting to dabble with bokeh-server and I’ve gone through the docs and I’m not finding anything for my specific use. In short, I’ve got a job that runs off of cron on a daily basis and outputs to my localhost with output_server.

So I’ve got output_server(‘foo’)

and then I’ve got ts1 and ts2, which are each a bokeh.chartsTimeSeries object

Once I’ve created them the first time, I just show(vplot(ts1, ts2)). However, I don’t want to create a new browser or browser tab every time this happens - I just want to update the doc on the server with the latest.

I’ve tried using save and push in lieu of show, but there’s something I’m missing. Any help and points to documentation would be most appreciated.

Best,

Jerrod

On Tuesday, March 3, 2015 at 7:28:24 AM UTC-8, [email protected] wrote:

Hi Bryan,

Thanks, this helps a lot. I had a vague idea about the two concepts, but your explanation really helps to clear up exactly what is going on.

Best,

Amy

On Tuesday, March 3, 2015 at 10:23:33 AM UTC-5, Bryan Van de ven wrote:

Hi ading,

Updating the Users Guide with some information about these things is on my very short list to-do this week. We have done some cleanup/refactoring around this part of Bokeh that should make things easier to explain and understand and to use, so it is a good time to do that. But in brief:

A session encapsulates a connection to a Bokeh-server. When you show() or push(), the value of cursession() lets those functions know what server to store data on.

A document is really a namespace for sharing objects. It is a collection of Bokeh objects that may refer to one another. Consider two plots that share a range in order to have linked panning. There would be a Document that contains both plots, and the shared range. Plots in different Documents have no way of “sharing” anything. A Document is really just a dictionary that maps unique IDs to Bokeh models. In order to facilitate this sharing, things like output_server() will create a “current” document for you, and this is the value of curdoc(). Documents are used in both static plots and bokeh server plots, it is an orthogonal concept to session.

Let me know if that clears up some of the concepts.

Thanks,

Bryan

On Mar 3, 2015, at 9:12 AM, [email protected] wrote:

Found a solution, using push() instead of show() the second time.

On Monday, March 2, 2015 at 5:03:00 PM UTC-5, [email protected] wrote:

(Apologies on the cross-post with SO. Searched for a solution but was still unable to resolve the issue)

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

()


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2f30f401-fcfb-4f0f-851e-c50f2e3ec4f4%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Amy -

Thanks for the replay and sorry for the delay!

I really appreciate the thoughtful response and example, but I’m still stuck. I think it’s mainly because I’m failing to grasp something that’s happening every time I launch a script. So let’s say I have the absurdly simple script below from the tutorial:

from bokeh.plotting import figure, output_server, cursession, Session, curdoc

output_server(‘myplot’)

create a Figure object

p = figure(width=300, height=300, tools=“pan,reset,save”)

add a Circle renderer to this figure

p.circle([1, 2.5, 3, 2], [2, 3, 1, 1.5], radius=0.3, alpha=0.5)

Let’s say that I’ve already output a document to the server, but for whatever reason I want to update it on a daily basis. I tried creating a new session and applying the store_object method on p, and same with cursession. After that, I tried publishing, and while the document appears, there’s nothing there when I click on it.

Sorry again for the trouble - a lot of great tutorials out there, but all of them use show, not publish, and alll I’m going off of is the 3 lines from here:

http://bokeh.pydata.org/en/latest/docs/user_guide/server.html

“or if you are using output server”

It makes it seem like all I need to do is output_server(‘name’), make plots, then cursession().publish(), but I have to assume there’s something implicit in there that I didn’t realize I needed to do.

Thanks again!

Jerrod

···

On Tue, Apr 21, 2015 at 12:12 PM, Amy Ding [email protected] wrote:

Here is what I have, hope it helps: My plots are all figures, with a collection of lines. For example,

plot1 = figure(title = ‘’, …)

plot1.line(x, y, …)

When creating plot1, I also save renderers[header].extend(plot.select(dict(type = GlyphRenderer))), where renderers is a list I keep, and header is like ‘plot1’

I initially show(plot1). To update the plots, I have a method like this:

def update_plots(header, df, renderers):

ds =

for i in range(0, len(renderers[header])):

r = renderers[header][i]

print r.name

r.data_source.data[‘x’] = df[‘x’]

r.data_source.data[‘y’] = df[‘y’]

ds.append(r.data_source)

cursession().store_objects(*ds)

This might be a bit of a round about way of going about it, now that I look back on it. In essence, what you are doing, is updating the data source for each plot, without actually re-showing the plots.

On Tue, Apr 21, 2015 at 11:52 AM, [email protected] wrote:

Hi all -

I think this is related (apologies if I’m off). I’m only just starting to dabble with bokeh-server and I’ve gone through the docs and I’m not finding anything for my specific use. In short, I’ve got a job that runs off of cron on a daily basis and outputs to my localhost with output_server.

So I’ve got output_server(‘foo’)

and then I’ve got ts1 and ts2, which are each a bokeh.chartsTimeSeries object

Once I’ve created them the first time, I just show(vplot(ts1, ts2)). However, I don’t want to create a new browser or browser tab every time this happens - I just want to update the doc on the server with the latest.

I’ve tried using save and push in lieu of show, but there’s something I’m missing. Any help and points to documentation would be most appreciated.

Best,

Jerrod

On Tuesday, March 3, 2015 at 7:28:24 AM UTC-8, [email protected] wrote:

Hi Bryan,

Thanks, this helps a lot. I had a vague idea about the two concepts, but your explanation really helps to clear up exactly what is going on.

Best,

Amy

On Tuesday, March 3, 2015 at 10:23:33 AM UTC-5, Bryan Van de ven wrote:

Hi ading,

Updating the Users Guide with some information about these things is on my very short list to-do this week. We have done some cleanup/refactoring around this part of Bokeh that should make things easier to explain and understand and to use, so it is a good time to do that. But in brief:

A session encapsulates a connection to a Bokeh-server. When you show() or push(), the value of cursession() lets those functions know what server to store data on.

A document is really a namespace for sharing objects. It is a collection of Bokeh objects that may refer to one another. Consider two plots that share a range in order to have linked panning. There would be a Document that contains both plots, and the shared range. Plots in different Documents have no way of “sharing” anything. A Document is really just a dictionary that maps unique IDs to Bokeh models. In order to facilitate this sharing, things like output_server() will create a “current” document for you, and this is the value of curdoc(). Documents are used in both static plots and bokeh server plots, it is an orthogonal concept to session.

Let me know if that clears up some of the concepts.

Thanks,

Bryan

On Mar 3, 2015, at 9:12 AM, [email protected] wrote:

Found a solution, using push() instead of show() the second time.

On Monday, March 2, 2015 at 5:03:00 PM UTC-5, [email protected] wrote:

(Apologies on the cross-post with SO. Searched for a solution but was still unable to resolve the issue)

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

()


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2f30f401-fcfb-4f0f-851e-c50f2e3ec4f4%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hi Jerrod,

Are you trying to update the plot manually? Or are you doing so in a while loop?

If you logic is as so:

while True:

update data sources

cursession().store_objects(*new data sources)

wait 24 hours

then the above should work. If it doesn’t work, can you attach a piece of your update code?

If what you’re trying to do is manually reference the same plot, say the next day, with the server still up, I’m not sure how you would go about doing so–I would create a new question with that specific question.

···

On Sat, Apr 25, 2015 at 2:01 PM, Jerrod Lowmaster [email protected] wrote:

Hi Amy -

Thanks for the replay and sorry for the delay!

I really appreciate the thoughtful response and example, but I’m still stuck. I think it’s mainly because I’m failing to grasp something that’s happening every time I launch a script. So let’s say I have the absurdly simple script below from the tutorial:

from bokeh.plotting import figure, output_server, cursession, Session, curdoc

output_server(‘myplot’)

create a Figure object

p = figure(width=300, height=300, tools=“pan,reset,save”)

add a Circle renderer to this figure

p.circle([1, 2.5, 3, 2], [2, 3, 1, 1.5], radius=0.3, alpha=0.5)

Let’s say that I’ve already output a document to the server, but for whatever reason I want to update it on a daily basis. I tried creating a new session and applying the store_object method on p, and same with cursession. After that, I tried publishing, and while the document appears, there’s nothing there when I click on it.

Sorry again for the trouble - a lot of great tutorials out there, but all of them use show, not publish, and alll I’m going off of is the 3 lines from here:

http://bokeh.pydata.org/en/latest/docs/user_guide/server.html

“or if you are using output server”

It makes it seem like all I need to do is output_server(‘name’), make plots, then cursession().publish(), but I have to assume there’s something implicit in there that I didn’t realize I needed to do.

Thanks again!

Jerrod

On Tue, Apr 21, 2015 at 12:12 PM, Amy Ding [email protected] wrote:

Here is what I have, hope it helps: My plots are all figures, with a collection of lines. For example,

plot1 = figure(title = ‘’, …)

plot1.line(x, y, …)

When creating plot1, I also save renderers[header].extend(plot.select(dict(type = GlyphRenderer))), where renderers is a list I keep, and header is like ‘plot1’

I initially show(plot1). To update the plots, I have a method like this:

def update_plots(header, df, renderers):

ds =

for i in range(0, len(renderers[header])):

r = renderers[header][i]

print r.name

r.data_source.data[‘x’] = df[‘x’]

r.data_source.data[‘y’] = df[‘y’]

ds.append(r.data_source)

cursession().store_objects(*ds)

This might be a bit of a round about way of going about it, now that I look back on it. In essence, what you are doing, is updating the data source for each plot, without actually re-showing the plots.

On Tue, Apr 21, 2015 at 11:52 AM, [email protected] wrote:

Hi all -

I think this is related (apologies if I’m off). I’m only just starting to dabble with bokeh-server and I’ve gone through the docs and I’m not finding anything for my specific use. In short, I’ve got a job that runs off of cron on a daily basis and outputs to my localhost with output_server.

So I’ve got output_server(‘foo’)

and then I’ve got ts1 and ts2, which are each a bokeh.chartsTimeSeries object

Once I’ve created them the first time, I just show(vplot(ts1, ts2)). However, I don’t want to create a new browser or browser tab every time this happens - I just want to update the doc on the server with the latest.

I’ve tried using save and push in lieu of show, but there’s something I’m missing. Any help and points to documentation would be most appreciated.

Best,

Jerrod

On Tuesday, March 3, 2015 at 7:28:24 AM UTC-8, [email protected] wrote:

Hi Bryan,

Thanks, this helps a lot. I had a vague idea about the two concepts, but your explanation really helps to clear up exactly what is going on.

Best,

Amy

On Tuesday, March 3, 2015 at 10:23:33 AM UTC-5, Bryan Van de ven wrote:

Hi ading,

Updating the Users Guide with some information about these things is on my very short list to-do this week. We have done some cleanup/refactoring around this part of Bokeh that should make things easier to explain and understand and to use, so it is a good time to do that. But in brief:

A session encapsulates a connection to a Bokeh-server. When you show() or push(), the value of cursession() lets those functions know what server to store data on.

A document is really a namespace for sharing objects. It is a collection of Bokeh objects that may refer to one another. Consider two plots that share a range in order to have linked panning. There would be a Document that contains both plots, and the shared range. Plots in different Documents have no way of “sharing” anything. A Document is really just a dictionary that maps unique IDs to Bokeh models. In order to facilitate this sharing, things like output_server() will create a “current” document for you, and this is the value of curdoc(). Documents are used in both static plots and bokeh server plots, it is an orthogonal concept to session.

Let me know if that clears up some of the concepts.

Thanks,

Bryan

On Mar 3, 2015, at 9:12 AM, [email protected] wrote:

Found a solution, using push() instead of show() the second time.

On Monday, March 2, 2015 at 5:03:00 PM UTC-5, [email protected] wrote:

(Apologies on the cross-post with SO. Searched for a solution but was still unable to resolve the issue)

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

()


You received this message because you are subscribed to the Google Groups “Bokeh Discussion - Public” group.

To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/2f30f401-fcfb-4f0f-851e-c50f2e3ec4f4%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.