Multiple Plots Backed by Different Datasets Updating Issue

Hello- I had posted this topic to stackoverflow but it would seem this is a better place for it. I am really enjoying working with the Bokeh library but I am a bit stuck and perhaps I need to take a different approach and use direct JSCallback?

down votefavorite

I have created two Bokeh plots backed by two different datasets which reside in the same html page. Both of these plots can be filtered via a MultiSelect widget. The page appears to load up ok (both plots look correct). When I click on one of the selectors the associated plot is updated correctly, and the other plot disappears (I think it actually squishes down into a column but hard to be sure). If I then click on the other selector (associated with the missing plot) the plot reappears and the first plot disappears.

I am using two “create_plot” functions:

def create_plot_1():
    #get data source, format plot, return plot
def create_plot_2():
    #get data source, format plot, return plot

I have two selectors:

selector_plot_1 = MultiSelect(title="MyOption1", options=myList1, value='AAA'
selector_plot_2 = MultiSelect(title="MyOption2", options=myList2, value='ZZZ'

I created two update functions one for each data source. I also created two distinct rows and add them to the curdoc.

def update1(attr, old, new):
    row1.children[1] = create_plot_1()
def update2(attr, old, new):
    row2.children[1] = create_plot_2()

selector_plot_1.on_change('value', update1)
selector_plot_2.on_change('value', update2)

row1 = row(selector_plot_1, create_plot_1() )
row2 = row(selector_plot_2, create_plot_2() )

curdoc().add_root(row1)
curdoc().add_root(row2)

What am I missing here on the update/on_change method? Is there a way to specify that only the elements in a given row are to be updated? Interestingly I have added two datatables which correspond to the data in the plots and these update correctly and display as expected. Let me know if you need any more info, I really appreciate any help!

Dennis

Hi Dennis,

Adding multiple roots to create a “layout” does not appear to be an intended feature of Bokeh. Multiple roots tend to cause problems that will break figures on update. Instead try combining row1 and row2 into a single layout object using column() and add the single layout object to the root of your current document instead. Below is a snippet illustrating what I mean.

def update1(attr, old, new):
    row1.children[1] = create_plot_1() def update2(attr, old, new):
    row2.children[1
] = create_plot_2()
selector_plot_1.on_change('value', update1)
selector_plot_2.on_change('value'
, update2)
row1 = row(selector_plot_1, create_plot_1() )
row2 = row(selector_plot_2, create_plot_2() )
# remove double root
# curdoc().add_root(row1)
# curdoc().add_root(row2)

# combine into a single layout
layout = column(row1, row2)
curdoc().add_root(layout)

···

On Tue, Apr 25, 2017 at 4:56 AM, Dennis Moccia [email protected] wrote:

Hello- I had posted this topic to stackoverflow but it would seem this is a better place for it. I am really enjoying working with the Bokeh library but I am a bit stuck and perhaps I need to take a different approach and use direct JSCallback?

down votefavorite

I have created two Bokeh plots backed by two different datasets which reside in the same html page. Both of these plots can be filtered via a MultiSelect widget. The page appears to load up ok (both plots look correct). When I click on one of the selectors the associated plot is updated correctly, and the other plot disappears (I think it actually squishes down into a column but hard to be sure). If I then click on the other selector (associated with the missing plot) the plot reappears and the first plot disappears.

I am using two “create_plot” functions:

def create_plot_1():
    #get data source, format plot, return plot
def create_plot_2():
    #get data source, format plot, return plot

I have two selectors:

selector_plot_1 = MultiSelect(title="MyOption1", options=myList1, value='AAA'
selector_plot_2 = MultiSelect(title="MyOption2", options=myList2, value='ZZZ'

I created two update functions one for each data source. I also created two distinct rows and add them to the curdoc.

def update1(attr, old, new):
    row1.children[1] = create_plot_1()
def update2(attr, old, new):
    row2.children[1] = create_plot_2()

selector_plot_1.on_change('value', update1)
selector_plot_2.on_change('value', update2)


row1 = row(selector_plot_1, create_plot_1() )
row2 = row(selector_plot_2, create_plot_2() )

curdoc().add_root(row1)
curdoc().add_root(row2)

What am I missing here on the update/on_change method? Is there a way to specify that only the elements in a given row are to be updated? Interestingly I have added two datatables which correspond to the data in the plots and these update correctly and display as expected. Let me know if you need any more info, I really appreciate any help!

Dennis

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/bfc8af23-0850-44b1-a818-b888f3e376e7%40continuum.io.

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

FYI There is work underway to support multiple roots with independent layouts.

Thanks,

Bryan

···

On Apr 25, 2017, at 12:42, Tyler Nickerson <[email protected]> wrote:

Hi Dennis,

Adding multiple roots to create a “layout” does not appear to be an intended feature of Bokeh. Multiple roots tend to cause problems that will break figures on update. Instead try combining row1 and row2 into a single layout object using column() and add the single layout object to the root of your current document instead. Below is a snippet illustrating what I mean.

def update1(attr, old, new):

    row1.children[
1
] = create_plot_1()

def update2(attr, old, new):

    row2.children[
1
] = create_plot_2()

selector_plot_1.on_change(
'value'
, update1)
selector_plot_2.on_change(
'value'
, update2)

row1 = row(selector_plot_1, create_plot_1() )
row2 = row(selector_plot_2, create_plot_2() )

# remove double root
# curdoc().add_root(row1)
# curdoc().add_root(row2)

# combine into a single layout

layout = column(row1, row2)
curdoc().add_root(layout)

On Tue, Apr 25, 2017 at 4:56 AM, Dennis Moccia <[email protected]> wrote:
Hello- I had posted this topic to stackoverflow but it would seem this is a better place for it. I am really enjoying working with the Bokeh library but I am a bit stuck and perhaps I need to take a different approach and use direct JSCallback?

down vote
favorite
I have created two Bokeh plots backed by two different datasets which reside in the same html page. Both of these plots can be filtered via a MultiSelect widget. The page appears to load up ok (both plots look correct). When I click on one of the selectors the associated plot is updated correctly, and the other plot disappears (I think it actually squishes down into a column but hard to be sure). If I then click on the other selector (associated with the missing plot) the plot reappears and the first plot disappears.

I am using two "create_plot" functions:

def create_plot_1():

#get data source, format plot, return plot
def create_plot_2():

#get data source, format plot, return plot
I have two selectors:

selector_plot_1 = MultiSelect(title="MyOption1", options=myList1, value='AAA'

selector_plot_2
= MultiSelect(title="MyOption2", options=myList2, value='ZZZ'
I created two update functions one for each data source. I also created two distinct rows and add them to the curdoc.

def update1(attr, old, new):

    row1
.children[1] = create_plot_1()
    
def update2(attr, old, new):

    row2
.children[1] = create_plot_2()

selector_plot_1
.on_change('value', update1)

selector_plot_2
.on_change('value', update2)

row1
= row(selector_plot_1, create_plot_1() )

row2
= row(selector_plot_2, create_plot_2() )

curdoc
().add_root(row1)

curdoc
().add_root(row2)
What am I missing here on the update/on_change method? Is there a way to specify that only the elements in a given row are to be updated? Interestingly I have added two datatables which correspond to the data in the plots and these update correctly and display as expected. Let me know if you need any more info, I really appreciate any help!

Dennis

--
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/bfc8af23-0850-44b1-a818-b888f3e376e7%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/CAAd1xFTiy86qYzz1w%2BO6te3KRuWf%3DJB_RjvM9%3DanOM2odSswsQ%40mail.gmail.com\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Bryan and Tyler, thanks for the reply on this, I actually figured out a way to handle this though admittedly it is not elegant!. I will post in case anyone is trying to pull this off prior to the new releases. I am new to Bokeh but would like to get involved in helping out once I ramp up. Great stuff here!

···

On Tue, Apr 25, 2017 at 6:47 PM Bryan Van de ven [email protected] wrote:

FYI There is work underway to support multiple roots with independent layouts.

Thanks,

Bryan

On Apr 25, 2017, at 12:42, Tyler Nickerson [email protected] wrote:

Hi Dennis,

Adding multiple roots to create a “layout” does not appear to be an intended feature of Bokeh. Multiple roots tend to cause problems that will break figures on update. Instead try combining row1 and row2 into a single layout object using column() and add the single layout object to the root of your current document instead. Below is a snippet illustrating what I mean.

def update1(attr, old, new):

row1.children[

1

] = create_plot_1()

def update2(attr, old, new):

row2.children[

1

] = create_plot_2()

selector_plot_1.on_change(

‘value’

, update1)

selector_plot_2.on_change(

‘value’

, update2)

row1 = row(selector_plot_1, create_plot_1() )

row2 = row(selector_plot_2, create_plot_2() )

remove double root

curdoc().add_root(row1)

curdoc().add_root(row2)

combine into a single layout

layout = column(row1, row2)

curdoc().add_root(layout)

On Tue, Apr 25, 2017 at 4:56 AM, Dennis Moccia [email protected] wrote:

Hello- I had posted this topic to stackoverflow but it would seem this is a better place for it. I am really enjoying working with the Bokeh library but I am a bit stuck and perhaps I need to take a different approach and use direct JSCallback?

down vote

favorite

I have created two Bokeh plots backed by two different datasets which reside in the same html page. Both of these plots can be filtered via a MultiSelect widget. The page appears to load up ok (both plots look correct). When I click on one of the selectors the associated plot is updated correctly, and the other plot disappears (I think it actually squishes down into a column but hard to be sure). If I then click on the other selector (associated with the missing plot) the plot reappears and the first plot disappears.

I am using two “create_plot” functions:

def create_plot_1():

#get data source, format plot, return plot

def create_plot_2():

#get data source, format plot, return plot

I have two selectors:

selector_plot_1 = MultiSelect(title=“MyOption1”, options=myList1, value=‘AAA’

selector_plot_2

= MultiSelect(title=“MyOption2”, options=myList2, value=‘ZZZ’

I created two update functions one for each data source. I also created two distinct rows and add them to the curdoc.

def update1(attr, old, new):

row1

.children[1] = create_plot_1()

def update2(attr, old, new):

row2

.children[1] = create_plot_2()

selector_plot_1

.on_change(‘value’, update1)

selector_plot_2

.on_change(‘value’, update2)

row1

= row(selector_plot_1, create_plot_1() )

row2

= row(selector_plot_2, create_plot_2() )

curdoc

().add_root(row1)

curdoc

().add_root(row2)

What am I missing here on the update/on_change method? Is there a way to specify that only the elements in a given row are to be updated? Interestingly I have added two datatables which correspond to the data in the plots and these update correctly and display as expected. Let me know if you need any more info, I really appreciate any help!

Dennis

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/bfc8af23-0850-44b1-a818-b888f3e376e7%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/CAAd1xFTiy86qYzz1w%2BO6te3KRuWf%3DJB_RjvM9%3DanOM2odSswsQ%40mail.gmail.com.

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/97210723-D63F-413F-BE2F-DDC1164420BA%40continuum.io.

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