The sample code couples an active Tab component with a (in)visible markdown component. The idea is to present a multi-segment panel where all of the segments are pre-rendered because the drawing times are sometimes too long for high-priced non-tech professionals to wait for. The multiple segments allow me to focus the plots so they can be expanded to full-screen without the text when needed.
Setting RUNPYTHON to True allows me to do quick exploring with the python syncing working great. My desire is setting it to False will use the jslink code instead, but that code is not producing similar results. I do not know if it is my lack of javascript experience, understanding the identifiers to use between the python bindings and the js/Bokeh bindings, or that a list of pn.Column items is just not accessible via jslink.
Any ideas/pointers?
import panel as pn
import holoviews as hv
hv.extension('bokeh', logo=False)
pn.extension()
pn.param.ParamMethod.loading_indicator = True
RUNPYTHON = False
tabs = pn.Tabs(
('first tab', 'first tab content'),
('second tab', 'second tab content'),
('third tab', 'third tab content'),
)
texts = pn.Column(
'first page comments',
'second page comments',
'third page comments',
)
def set_cur_text(texts, tabs):
for i in range(len(texts)):
texts[i].visible = (i == tabs.active)
set_cur_text(texts, tabs)
def match_text(*events):
for event in events:
if event.name == 'active':
texts[event.old].visible = False
texts[event.new].visible = True
if RUNPYTHON:
watchtabs = tabs.param.watch(match_text, ['active'], onlychanged=True)
tabs.param.trigger('active')
else:
# jscode = '''
# for (i = 0; i < target.length; i++) {
# target[i].visible = (i == source.active);
# }
# '''
jscode = '''
target[source.old].visible = false;
target[source.new].visible = true
target.change.emit()
'''
link = tabs.jslink(texts, code={'active': jscode})
app = pn.template.FastGridTemplate()
app.main[:8, :3] = texts
app.main[:8, 3:] = tabs
app.show()