Skip to content

Trouble Swapping out layout contents when using server #4810

Description

@brendancol

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions