dynamic update of a figure with new columns to columndatasource

Hello,

Using the server, I try to add new lines to a figure when pressing one of the two buttons (top button: one new line at a time, below: three new lines at a time).

I have a hard time to make it work properly: the top button works from time to time (never the 2nd time), and seems to depend on the time I am waiting between two clicks. When the interval is too short, it bugs quickly, nothing happens anymore.

The button below is behaving even worse, never get the three new lines.

Moreover, the printed columndatasource seems to loose columns. With larger arrays, lines start flickering.

What is the proper way to use bokeh for dynamic addition of new lines ?

Is there some timeout to respect between operations linking the server and the client ?

from bokeh.plotting import figure

from bokeh.io import curdoc,output_file, show

from bokeh.models import ColumnDataSource

from bokeh.models.widgets import Button

from bokeh.layouts import column

def b_cb():

global i

i+=1

s = c.add([el+i for el in y])

p.line(x=‘x’,y=s, source=c)

print(c.column_names)

def b2_cb():

global i

i+=3

for j in range(3):

s = c.add([el+i+j for el in y])

p.line(x=‘x’,y=s, source=c)

print(c.column_names)

b=Button()

b.on_click(b_cb)

b2=Button()

b2.on_click(b2_cb)

x=[-10,10,20];y=[-2,2,5]

i=0

c=ColumnDataSource(dict(x=x,y=y))

p = figure(plot_width=400, plot_height=400)

curdoc().add_root(column(b,b2,p))

I believe there are some known issues with *adding* new models to a document in some cases that still need to be resolved. Rather then trying to *add* new lines on demand, I'd first suggest that for now, a much more robust would be to *update* existing lines. Add a bunch of (invisible) line renderers up front, and use the buttons to hide/show them, or to update their existing data sources, which is also a well-established practice.

Thanks,

Bryan

···

On Dec 11, 2016, at 2:01 PM, chupach <[email protected]> wrote:

Hello,

Using the server, I try to add new lines to a figure when pressing one of the two buttons (top button: one new line at a time, below: three new lines at a time).

I have a hard time to make it work properly: the top button works from time to time (never the 2nd time), and seems to depend on the time I am waiting between two clicks. When the interval is too short, it bugs quickly, nothing happens anymore.

The button below is behaving even worse, never get the three new lines.
Moreover, the printed columndatasource seems to loose columns. With larger arrays, lines start flickering.

What is the proper way to use bokeh for dynamic addition of new lines ?
Is there some timeout to respect between operations linking the server and the client ?

from bokeh.plotting import figure
from bokeh.io import curdoc,output_file, show
from bokeh.models import ColumnDataSource
from bokeh.models.widgets import Button
from bokeh.layouts import column

def b_cb():
    global i
    i+=1
    s = c.add([el+i for el in y])
    p.line(x='x',y=s, source=c)
    print(c.column_names)

def b2_cb():
    global i
    i+=3
    for j in range(3):
      s = c.add([el+i+j for el in y])
      p.line(x='x',y=s, source=c)
    print(c.column_names)

b=Button()
b.on_click(b_cb)
b2=Button()
b2.on_click(b2_cb)

x=[-10,10,20];y=[-2,2,5]
i=0
c=ColumnDataSource(dict(x=x,y=y))

p = figure(plot_width=400, plot_height=400)
curdoc().add_root(column(b,b2,p))

--
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/23442e6a-cb7f-441b-861d-6c836109d1e0%40continuum.io.
For more options, visit https://groups.google.com/a/continuum.io/d/optout.

Hello Bryan,
Thank you for the quick reply.

then i will add the dummy renderers and dummy columns from start.

It seems that nan values in the dummy columns are fine to make them invisible

Thx again.

···

On Monday, December 12, 2016 at 12:27:10 AM UTC+1, Bryan Van de ven wrote:

I believe there are some known issues with adding new models to a document in some cases that still need to be resolved. Rather then trying to add new lines on demand, I’d first suggest that for now, a much more robust would be to update existing lines. Add a bunch of (invisible) line renderers up front, and use the buttons to hide/show them, or to update their existing data sources, which is also a well-established practice.

Thanks,

Bryan

On Dec 11, 2016, at 2:01 PM, chupach [email protected] wrote:

Hello,

Using the server, I try to add new lines to a figure when pressing one of the two buttons (top button: one new line at a time, below: three new lines at a time).

I have a hard time to make it work properly: the top button works from time to time (never the 2nd time), and seems to depend on the time I am waiting between two clicks. When the interval is too short, it bugs quickly, nothing happens anymore.

The button below is behaving even worse, never get the three new lines.

Moreover, the printed columndatasource seems to loose columns. With larger arrays, lines start flickering.

What is the proper way to use bokeh for dynamic addition of new lines ?

Is there some timeout to respect between operations linking the server and the client ?

from bokeh.plotting import figure

from bokeh.io import curdoc,output_file, show

from bokeh.models import ColumnDataSource

from bokeh.models.widgets import Button

from bokeh.layouts import column

def b_cb():

global i
i+=1
s = c.add([el+i for el in y])
p.line(x='x',y=s, source=c)
print(c.column_names)

def b2_cb():

global i
i+=3
for j in range(3):
  s = c.add([el+i+j for el in y])
  p.line(x='x',y=s, source=c)
print(c.column_names)

b=Button()

b.on_click(b_cb)

b2=Button()

b2.on_click(b2_cb)

x=[-10,10,20];y=[-2,2,5]

i=0

c=ColumnDataSource(dict(x=x,y=y))

p = figure(plot_width=400, plot_height=400)

curdoc().add_root(column(b,b2,p))


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/23442e6a-cb7f-441b-861d-6c836109d1e0%40continuum.io.

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

Hello,
As I did not easily realise from the doc and forums how to dynamically add lines to a figure, here is the relevant code which now works without any glitch. As Bryan suggested, better not to change the shape of a columndatasource or add new models dynamically at the moment.

They should be present from the beginning: all lines sourced with columns filled with nan values. When hitting the button, three line sources are updated at once.

from bokeh.plotting import figure

from bokeh.io import curdoc

from bokeh.models import ColumnDataSource

from bokeh.models.widgets import Button

from bokeh.layouts import column

import numpy as np

def b_cb():

global i

for j in range(3): c.data[‘serie_’+str(i+j)]=[el+i+j for el in y]

i+=3

b = Button()

b.on_click(b_cb)

i,n = 0,50

x,y = list(range(n)),[-2,2,1,0,-3]*10

p, dico = figure(), {‘serie_’+str(k):[np.nan]*n for k in range(n)}

dico[‘x’]=x; c = ColumnDataSource(dico)

for k in range(n): p.line(x=‘x’,y=‘serie_’+str(k), source=c)

curdoc().add_root(column(b,p))

···

On Monday, December 12, 2016 at 12:43:44 AM UTC+1, chupach wrote:

Hello Bryan,
Thank you for the quick reply.

then i will add the dummy renderers and dummy columns from start.

It seems that nan values in the dummy columns are fine to make them invisible

Thx again.

On Monday, December 12, 2016 at 12:27:10 AM UTC+1, Bryan Van de ven wrote:

I believe there are some known issues with adding new models to a document in some cases that still need to be resolved. Rather then trying to add new lines on demand, I’d first suggest that for now, a much more robust would be to update existing lines. Add a bunch of (invisible) line renderers up front, and use the buttons to hide/show them, or to update their existing data sources, which is also a well-established practice.

Thanks,

Bryan

On Dec 11, 2016, at 2:01 PM, chupach [email protected] wrote:

Hello,

Using the server, I try to add new lines to a figure when pressing one of the two buttons (top button: one new line at a time, below: three new lines at a time).

I have a hard time to make it work properly: the top button works from time to time (never the 2nd time), and seems to depend on the time I am waiting between two clicks. When the interval is too short, it bugs quickly, nothing happens anymore.

The button below is behaving even worse, never get the three new lines.

Moreover, the printed columndatasource seems to loose columns. With larger arrays, lines start flickering.

What is the proper way to use bokeh for dynamic addition of new lines ?

Is there some timeout to respect between operations linking the server and the client ?

from bokeh.plotting import figure

from bokeh.io import curdoc,output_file, show

from bokeh.models import ColumnDataSource

from bokeh.models.widgets import Button

from bokeh.layouts import column

def b_cb():

global i
i+=1
s = c.add([el+i for el in y])
p.line(x='x',y=s, source=c)
print(c.column_names)

def b2_cb():

global i
i+=3
for j in range(3):
  s = c.add([el+i+j for el in y])
  p.line(x='x',y=s, source=c)
print(c.column_names)

b=Button()

b.on_click(b_cb)

b2=Button()

b2.on_click(b2_cb)

x=[-10,10,20];y=[-2,2,5]

i=0

c=ColumnDataSource(dict(x=x,y=y))

p = figure(plot_width=400, plot_height=400)

curdoc().add_root(column(b,b2,p))


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/23442e6a-cb7f-441b-861d-6c836109d1e0%40continuum.io.

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