Update ColumnDataSource in App

Hey Everybody .

I have some trouble by updating my ColumnDataSource. I don’t get what I’m doing wrong. I guess a beginner mistake . I just don’t
get it alone. Every advice will be veryyy helpfull .

What happened is : I get the plot done and I can update one time with one value of the select widget and it is blocked.

Thank you in advance for your help

Rémi

My code

source= ColumnDataSource( DataforPlot(Prod_name[0]) )
#source.column_names =>
#[‘RUBAX TABL MONO 100 MG 80’, ‘RUBAX TABL MONO 100 MG 20’,
#‘RUBAX TROPF 1 30 ML’, ‘RUBAX TROPF 1 10 ML’, ‘ProductSales’,
#RUBAX TABL MONO 100 MG 40’, ‘dates’]

···

#==============================================================================

Plot

#==============================================================================

Create figure

Toolbox= “pan,box_zoom,reset,save”
p = figure(x_axis_type=‘datetime’,plot_width=700, plot_height=500,
tools=Toolbox, title=“my sine wave”,)
p.xaxis.formatter=DatetimeTickFormatter(formats=dict(
months=[" %B %Y"],
years= [" %B %Y"], ))
p.xaxis.major_label_orientation = pi/4
p.xgrid[0].ticker.desired_num_ticks = 10
p.xaxis.axis_label = ‘Date’
text = TextInput(title=“title”, value=’ desactivate ! ')

draw line

y=‘ProductSales’
p.line( x=‘dates’ ,y=y , source=source)

update line fucntion

def update_plot(attr,old,new):

p.title.text = select.value

# get the new y data to draw the line
y= source.data.get(select.value)
x= source.data.get('dates')

#update source
source.data= dict(x=x, y=y)
#new line to draw !
p.line( x='dates' ,y=y , source=source)

create Widget

select = Select(title=“OTC Product:”, value=’ Product’, options= source.column_names)
select.on_change(“value”, update_plot)

``

Hi Remi,

I think the issue you’re having has to do with your approach to updating the column data source. First the callback gets it’s new values from source.data:

    # get the new y data to draw the line
    y= source.data.get(select.value)
x= source.data.get('dates')

Then you update source.data with only those two values, renamed to ‘x’ and ‘y’ respectively:

    #update source
    source.data= dict(x=x, y=y)

After this line is executed the column data source only has two columns: ‘x’ and ‘y’. The next time that update_plot() is called, the function searches source.data for the key values 'dates' and select.value which both return nothing because those columns no longer exist in source.data. I think the easiest fix would be to store the data set that is used to update source.data separately from source.data.

Also, p.line( x='dates' ,y=y , source=source) does not need to be included in update_plot(). Updating a column data source should update all glyphs linked to that source.

Hope that helps,
Tyler

···

On Thu, Mar 2, 2017 at 10:25 AM, Rémi Toudic [email protected] wrote:

Hey Everybody .

I have some trouble by updating my ColumnDataSource. I don’t get what I’m doing wrong. I guess a beginner mistake . I just don’t
get it alone. Every advice will be veryyy helpfull .

What happened is : I get the plot done and I can update one time with one value of the select widget and it is blocked.

Thank you in advance for your help

Rémi

My code

source= ColumnDataSource( DataforPlot(Prod_name[0]) )
#source.column_names =>
#[‘RUBAX TABL MONO 100 MG 80’, ‘RUBAX TABL MONO 100 MG 20’,
#‘RUBAX TROPF 1 30 ML’, ‘RUBAX TROPF 1 10 ML’, ‘ProductSales’,
#RUBAX TABL MONO 100 MG 40’, ‘dates’]
#==============================================================================

Plot

#==============================================================================

Create figure

Toolbox= “pan,box_zoom,reset,save”
p = figure(x_axis_type=‘datetime’,plot_width=700, plot_height=500,
tools=Toolbox, title=“my sine wave”,)
p.xaxis.formatter=DatetimeTickFormatter(formats=dict(
months=[" %B %Y"],
years= [" %B %Y"], ))
p.xaxis.major_label_orientation = pi/4
p.xgrid[0].ticker.desired_num_ticks = 10
p.xaxis.axis_label = ‘Date’
text = TextInput(title=“title”, value=’ desactivate ! ')

draw line

y=‘ProductSales’
p.line( x=‘dates’ ,y=y , source=source)

update line fucntion

def update_plot(attr,old,new):

p.title.text = select.value

# get the new y data to draw the line
y= source.data.get(select.value)
x= source.data.get('dates')

#update source
source.data= dict(x=x, y=y)
#new line to draw !
p.line( x='dates' ,y=y , source=source)

create Widget

select = Select(title=“OTC Product:”, value=’ Product’, options= source.column_names)
select.on_change(“value”, update_plot)

``

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/d3e18d13-5eb1-4226-827e-45ee153fd711%40continuum.io.

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

Thank you very much for taking time reading my code . I had also the feeling than my approach was not right . Thank you for yours advices .

I really like Bokeh and all the commuity behind it.

Nice weekend to all of you .

best
Rémi

···

On Thursday, March 2, 2017 at 8:32:16 PM UTC+1, Tyler Nickerson wrote:

Hi Remi,

I think the issue you’re having has to do with your approach to updating the column data source. First the callback gets it’s new values from source.data:

    # get the new y data to draw the line
    y= source.data.get(select.value)
x= source.data.get('dates')

Then you update source.data with only those two values, renamed to ‘x’ and ‘y’ respectively:

    #update source
    source.data= dict(x=x, y=y)

After this line is executed the column data source only has two columns: ‘x’ and ‘y’. The next time that update_plot() is called, the function searches source.data for the key values 'dates' and select.value which both return nothing because those columns no longer exist in source.data. I think the easiest fix would be to store the data set that is used to update source.data separately from source.data.

Also, p.line( x='dates' ,y=y , source=source) does not need to be included in update_plot(). Updating a column data source should update all glyphs linked to that source.

Hope that helps,
Tyler

On Thu, Mar 2, 2017 at 10:25 AM, Rémi Toudic [email protected] wrote:

Hey Everybody .

I have some trouble by updating my ColumnDataSource. I don’t get what I’m doing wrong. I guess a beginner mistake . I just don’t
get it alone. Every advice will be veryyy helpfull .

What happened is : I get the plot done and I can update one time with one value of the select widget and it is blocked.

Thank you in advance for your help

Rémi

My code

source= ColumnDataSource( DataforPlot(Prod_name[0]) )
#source.column_names =>
#[‘RUBAX TABL MONO 100 MG 80’, ‘RUBAX TABL MONO 100 MG 20’,
#‘RUBAX TROPF 1 30 ML’, ‘RUBAX TROPF 1 10 ML’, ‘ProductSales’,
#RUBAX TABL MONO 100 MG 40’, ‘dates’]
#==============================================================================

Plot

#==============================================================================

Create figure

Toolbox= “pan,box_zoom,reset,save”
p = figure(x_axis_type=‘datetime’,plot_width=700, plot_height=500,
tools=Toolbox, title=“my sine wave”,)
p.xaxis.formatter=DatetimeTickFormatter(formats=dict(
months=[" %B %Y"],
years= [" %B %Y"], ))
p.xaxis.major_label_orientation = pi/4
p.xgrid[0].ticker.desired_num_ticks = 10
p.xaxis.axis_label = ‘Date’
text = TextInput(title=“title”, value=’ desactivate ! ')

draw line

y=‘ProductSales’
p.line( x=‘dates’ ,y=y , source=source)

update line fucntion

def update_plot(attr,old,new):

p.title.text = select.value

# get the new y data to draw the line
y= source.data.get(select.value)
x= source.data.get('dates')

#update source
source.data= dict(x=x, y=y)
#new line to draw !
p.line( x='dates' ,y=y , source=source)

create Widget

select = Select(title=“OTC Product:”, value=’ Product’, options= source.column_names)
select.on_change(“value”, update_plot)

``

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/d3e18d13-5eb1-4226-827e-45ee153fd711%40continuum.io.

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

No problem. I’m glad I could help!

···

On Fri, Mar 3, 2017 at 2:39 AM, Rémi Toudic [email protected] wrote:

Thank you very much for taking time reading my code . I had also the feeling than my approach was not right . Thank you for yours advices .

I really like Bokeh and all the commuity behind it.

Nice weekend to all of you .

best
Rémi

On Thursday, March 2, 2017 at 8:32:16 PM UTC+1, Tyler Nickerson wrote:

Hi Remi,

I think the issue you’re having has to do with your approach to updating the column data source. First the callback gets it’s new values from source.data:

    # get the new y data to draw the line
    y= source.data.get(select.value)
x= source.data.get('dates')

Then you update source.data with only those two values, renamed to ‘x’ and ‘y’ respectively:

    #update source
    source.data= dict(x=x, y=y)

After this line is executed the column data source only has two columns: ‘x’ and ‘y’. The next time that update_plot() is called, the function searches source.data for the key values 'dates' and select.value which both return nothing because those columns no longer exist in source.data. I think the easiest fix would be to store the data set that is used to update source.data separately from source.data.

Also, p.line( x='dates' ,y=y , source=source) does not need to be included in update_plot(). Updating a column data source should update all glyphs linked to that source.

Hope that helps,
Tyler

On Thu, Mar 2, 2017 at 10:25 AM, Rémi Toudic [email protected] wrote:

Hey Everybody .

I have some trouble by updating my ColumnDataSource. I don’t get what I’m doing wrong. I guess a beginner mistake . I just don’t
get it alone. Every advice will be veryyy helpfull .

What happened is : I get the plot done and I can update one time with one value of the select widget and it is blocked.

Thank you in advance for your help

Rémi

My code

source= ColumnDataSource( DataforPlot(Prod_name[0]) )
#source.column_names =>
#[‘RUBAX TABL MONO 100 MG 80’, ‘RUBAX TABL MONO 100 MG 20’,
#‘RUBAX TROPF 1 30 ML’, ‘RUBAX TROPF 1 10 ML’, ‘ProductSales’,
#RUBAX TABL MONO 100 MG 40’, ‘dates’]
#==============================================================================

Plot

#==============================================================================

Create figure

Toolbox= “pan,box_zoom,reset,save”
p = figure(x_axis_type=‘datetime’,plot_width=700, plot_height=500,
tools=Toolbox, title=“my sine wave”,)
p.xaxis.formatter=DatetimeTickFormatter(formats=dict(
months=[" %B %Y"],
years= [" %B %Y"], ))
p.xaxis.major_label_orientation = pi/4
p.xgrid[0].ticker.desired_num_ticks = 10
p.xaxis.axis_label = ‘Date’
text = TextInput(title=“title”, value=’ desactivate ! ')

draw line

y=‘ProductSales’
p.line( x=‘dates’ ,y=y , source=source)

update line fucntion

def update_plot(attr,old,new):

p.title.text = select.value

# get the new y data to draw the line
y= source.data.get(select.value)
x= source.data.get('dates')

#update source
source.data= dict(x=x, y=y)
#new line to draw !
p.line( x='dates' ,y=y , source=source)

create Widget

select = Select(title=“OTC Product:”, value=’ Product’, options= source.column_names)
select.on_change(“value”, update_plot)

``

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/d3e18d13-5eb1-4226-827e-45ee153fd711%40continuum.io.

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

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/b7df36f1-f490-4e99-8cbb-508631123617%40continuum.io.

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