0

I'm trying to do a text input where user can write the plot that they want to show. For example if user type "plot 1", only plot 1 is shown in the checkbox and user can click to activate/deactivate the chart

from bokeh.io import output_file, show
from bokeh.layouts import column, row
from bokeh.plotting import figure
from bokeh.models import CheckboxGroup, CustomJS, TextInput, Div

output_file("layout.html")

x = list(range(11))
y0 = x
y1 = [10 - i for i in x]
y2 = [abs(i - 5) for i in x]

s1 = figure(plot_width=250, plot_height=250, title=None)
s1.circle(x, y0, size=10, color="navy", alpha=0.5)

s2 = figure(plot_width=250, plot_height=250, title=None)
s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)

s3 = figure(plot_width=250, plot_height=250, title=None)
s3.square(x, y2, size=10, color="olive", alpha=0.5)

col = column(s1, s2, s3)

"text input"

textinput = TextInput(value="Plot 1", title="plot")

labels=["Plot 1", "Plot 2", "Plot 3"]

label2=[]
checkbox = CheckboxGroup(labels=labels,
                         active=[0, 1, 2], width=100)

callback = CustomJS(args=dict(plots=[s1,s2, s3], col=col, checkbox=checkbox, labels=labels, textinput=textinput, label2=label2) , code="""
const children = []
for (const i of checkbox.active) {
     children.push(plots[i])
} 
col.children = children

var label2=labels
label2.push(String(textinput.value))
checkbox.labels=label2
"""

)

checkbox.js_on_change('active', callback)


show(row(textinput,checkbox, col))
bag3r0
  • 1

0 Answers0