I’d like to use both widgets to display predefined text based on the selection (similar idea like here: Interactive Visualization of Australian Wine Ratings - Practical Business Python ).
More precisely:
select: “A” → display: “sample text”
select: “B” → display: “works”
Anyone can help? No JS if possible, please.
Just change Div.text
in your Python callback that reacts to the select’s value change. Note that it will work only if you’re using bokeh serve
. If you aren’t, then there will have to be some JS, but it will be just 1-2 lines.
Thanks Eugene,
This is what I’ve manage to invent. Unfortunately it doesn’t work. Can you please point out what and how should be corrected?
select_biplot = Select(title = 'Select Biplot', value = 'SYM', options = ['SYM', 'COV', 'JK'])
SYM = """SYM Your For this example"""
COV = """COV Your For this example"""
JK = """JK Your For this example"""
div_biplot = Paragraph(text=SYM, width=240, css_classes=['div_biplot'])
menu_biplot = Column(select_biplot, div_biplot, name='menu_biplot', width=250)
def biplot_callback(attrname, old, new):
if select_biplot.value == 'COV':
Paragraph.text=COV
elif select_biplot.value == 'JK':
Paragraph.text=JK
else:
Paragraph.text=SYM
select_biplot.on_change('value', biplot_callback)
curdoc().add_root(menu_biplot)
_jm
June 12, 2020, 12:11pm
4
@grzegorz.malinowski
Your callback is modifying the bokeh core model Paragraph
, but you need to operate on your specific model, div_biplot
.
Your callback should be something like the following.
def biplot_callback(attrname, old, new):
if new == 'COV':
div_biplot.text=COV
elif new == 'JK':
div_biplot.text=JK
else:
div_biplot.text=SYM
Thank you. Works. Theoretically, would it be possible to use dict for that?