Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble Swapping out layout contents when using server #4810

Closed
brendancol opened this issue Jul 15, 2016 · 4 comments
Closed

Trouble Swapping out layout contents when using server #4810

brendancol opened this issue Jul 15, 2016 · 4 comments

Comments

@brendancol
Copy link

@brendancol brendancol commented Jul 15, 2016

I'm looking for a simple way to swap out figures inside a layout...basically hiding one figure and displaying another. Below I have an example of my intent. What Im seeing is that when a figure is dynamically added to a Column, its plot_height/plot_width is set to 0.

Example:

from bokeh.io import curdoc
from bokeh.plotting import Figure
from bokeh.models import Row, Column, Button
from random import randint

def _create_fig():
    fig = Figure(plot_width=100, plot_height=100)
    fig.circle(x=0, y=0)
    return fig

def callback():
    num = randint(0,9)
    if num > 5:
        fig1_col.children = [_create_fig()]
        fig2_col.children = []
    else:
        fig2_col.children = [_create_fig()]
        fig1_col.children = []

fig1 = _create_fig()
fig2 = _create_fig()
button = Button()
button.on_click(callback)

button_row = Row(children=[button])

fig1_col = Column(children=[fig1])
fig2_col = Column(children=[fig2])

fig_row = Row(children=[fig1_col, fig2_col])

layout = Column(children=[button_row, fig_row])
curdoc().add_root(layout)
@brendancol
Copy link
Author

@brendancol brendancol commented Jul 18, 2016

funny enough, the example above works if empty column line is execute before re-populating the columns:

fig2_col.children = []
fig1_col.children = [_create_fig()]
@bryevdv
Copy link
Member

@bryevdv bryevdv commented Mar 24, 2017

ping @mattpap I think this might be a dupe, or if not, might be covered by your ongoing layout work. Moving to 0.12.6 to keep track

@bryevdv bryevdv modified the milestones: 0.12.6, short-term Mar 24, 2017
@mattpap
Copy link
Contributor

@mattpap mattpap commented Mar 24, 2017

Definitively a duplicate, though I'm not sure of which issue (there are a few). This will be fixed (or already is) in PR #5976.

@mattpap mattpap mentioned this issue Mar 28, 2017
1 of 2 tasks complete
@bryevdv
Copy link
Member

@bryevdv bryevdv commented Jun 1, 2017

Just confirming that this is not fixed by any work up to 0.12.6dev7

Also here is updated code:

from bokeh.io import curdoc
from bokeh.plotting import figure
from bokeh.layouts import row, column
from bokeh.models import Button
from random import randint

def _create_fig():
    fig = figure(plot_width=200, plot_height=200)
    fig.circle(x=0, y=0)
    return fig

def callback():
    num = randint(0,9)
    if num > 5:
        fig1_col.children = [_create_fig()]
        fig2_col.children = []
    else:
        fig2_col.children = [_create_fig()]
        fig1_col.children = []

fig1 = _create_fig()
fig2 = _create_fig()
button = Button()
button.on_click(callback)

button_row = row(button)

fig1_col = column(fig1)
fig2_col = column(fig2)

fig_row = row(fig1_col, fig2_col)

layout = column(button_row, fig_row)
curdoc().add_root(layout)

It sort of works sometimes, but toolbars aren't showing up. ALso lots of log messages like:

2017-05-31 19:48:44,997 error handling message Message 'PATCH-DOC' (revision 1): RuntimeError('Cannot apply patch to 34f81d6c-3342-418f-8455-0b7f24edfdd6 which is not in the document',)
2017-05-31 19:48:44,998 error handling message Message 'PATCH-DOC' (revision 1): RuntimeError('Cannot apply patch to 34f81d6c-3342-418f-8455-0b7f24edfdd6 which is not in the document',)
2017-05-31 19:48:45,547 error handling message Message 'PATCH-DOC' (revision 1): RuntimeError('Cannot apply patch to 9173ba81-8fd5-4eb2-bee7-2ab6b94263f0 which is not in the document',)
2017-05-31 19:48:45,549 error handling message Message 'PATCH-DOC' (revision 1): RuntimeError('Cannot apply patch to 9173ba81-8fd5-4eb2-bee7-2ab6b94263f0 which is not in the document',)
2017-05-31 19:48:45,550 error handling message Message 'PATCH-DOC' (revision 1): RuntimeError('Cannot apply patch to 9173ba81-8fd5-4eb2-bee7-2ab6b94263f0 which is not in the document',)
2017-05-31 19:48:45,551 error handling message Message 'PATCH-DOC' (revision 1): RuntimeError('Cannot apply patch to 9173ba81-8fd5-4eb2-bee7-2ab6b94263f0 which is not in the document',)

Guessing there is a problem synching models that have references to other new models and/or removing entire models.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.