Changing visbility damages layout

I have a custom layout built with row and column. Changing visibility messes with the layout.

from bokeh.io import curdoc
from bokeh.models.widgets import RadioGroup, Toggle
from bokeh.layouts import row, column


class JustSomeButtons:
    """ Some buttons.
    """

    def __init__(self):
        self._my_layout = row(
            column(
                RadioGroup(labels=["1", "2"], active=0),
                RadioGroup(labels=["3", "4"], active=1),
            ),
            column(
                RadioGroup(labels=["5", "6", "7"], active=2),
                RadioGroup(labels=["8", "9"], active=0),
            ),
        )
        toggle_visibility = Toggle(label="Show / Unshow", active=True)
        toggle_visibility.on_change("active", self.update)
        curdoc().add_root(column(toggle_visibility, self._my_layout))

    def update(self, attr, old, new):  # pylint: disable=unused-argument
        """ Update buttons visibility.
        """
        self._my_layout.visible = new


def main():
    """ Here we create the object.
    """
    JustSomeButtons()


if __name__.startswith("bk_script"):
    main()

After hiding and making visible again the grid of buttons:

Am I doing something wrong? Is there a way to force recomputing the correct locations?

bokeh 1.4.0
Firefox 73.0 (64-bit)
Google Chrome 80.0.3987.106 (Official Build) (64-bit)

I don’t know offhand, I will have to actually try the code when I can get a chance. But I wanted to immediately mention that you should not rely on this:

That is (intentionally) not documented, is entirely subject to change (and in fact will be be changing in the next release).

1 Like

This works for me. I don’t know why, but hiding the Widgets directly solves my problem.

from bokeh.models.layouts import Box

[...]

def update(self, attr, old, new):  # pylint: disable=unused-argument
    """ Update buttons visibility.
    """
    stack = [self._my_layout]
    while stack:
        some_layout = stack.pop()
        if isinstance(some_layout, Box):
            for model in some_layout.children:
                stack.append(model)
        else:
            some_layout.visible = new
1 Like

Offhand seems like a bug.