ENVIRONMENT
panel 0.12.0
bokeh 2.3.3
python 3.9.6
BACKGROUND: See this earlier topic for context.
ISSUE: Although layout elements have a visible property in panel 0.12.0, unexpected behavior is observed when dynamically setting this as part of an application served via panel serve ...
The following is a minimal reproducible example illustrating the problem. In short, once the visible property of the panel Card
is set to False
, it never shows again even if the property is changed; the property value and the state in the browser are inconsistent thereafter.
The code includes a vis_init
variable that one can change to see the nuances of this behavior.
If the value is True
, the Card is displayed at startup, which is expected, pressing the button makes the Card disappear, which is also expected, but subsequent button presses do not cause the Card
to display, which is unexpected.
If the value is False
, the Card
is not displayed from the outset, which is expected, but it cannot be made to render by changing its visible
property, which is unexpected.
The companion Div
element updates consistently with the button presses.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
"""
import panel as pn
from bokeh.models import Button, Div
vis_init = True
b = Button(button_type='primary', width=100, label='Show/Hide')
c = pn.Card(title='Analysis Results', visible=vis_init)
d = Div(text='lorem ipsum', visible=vis_init)
def show_cb():
c.visible = not c.visible
d.visible = not d.visible
print("INFO | card visible? {:} | div visible? {:}|".format(c.visible, d.visible))
print("")
b.on_click(show_cb)
pn.Column(b,c,d).servable()