I want to create a visualization with CheckboxGroup
and ‘Button’, which shows the line of the currency in the graph if the checkbox of this currency is activated. In addition i want one Button ‘Select all’ and one ‘Select none’ to select all or none currency at once.
By now, I have this code but I get the following error and I don’t know what to write in ‘code’. In general I am pretty lost regarding the callbacks of CheckbockGroup and Button. I would really appreciate a check of my code and some help. Thank you!
unexpected attribute ‘checkbox’ to CustomJS, possible attributes are args, code, js_event_callbacks, js_property_callbacks, name, subscribed_events or tags
import pandas as pd
from bokeh.io import output_file, show, save
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, HoverTool, CheckboxGroup, CustomJS, Button
from bokeh.layouts import row, column
...
source_dict = {'dates': dates}
for c in currencies:
source_dict[c] = df_returns.loc[:,c].values.tolist()
source = ColumnDataSource(data=source_dict)
p = figure(plot_width=1000, plot_height=800, x_axis_type="datetime")
p.title.text = 'Daily Returns during 2020'
lines = []
names = []
args = []
for c in range(len(currencies)):
line = p.line(x='dates', y=currencies[c], line_width=2, alpha=1, name=currencies[c], legend_label=currencies[c], source=source)
lines.append(line)
names.append(currencies[c])
args += [('line'+str(c), line)]
p.sizing_mode = "stretch_width"
p.legend.visible = False
hover = HoverTool(tooltips=[("date", "@dates{%F}"),
('currency','$name'),
('return','@$name{0.00%}')],
formatters={'@dates': 'datetime'})
p.add_tools(hover)
checkbox_group = CheckboxGroup(labels=names, active=list(range(len(currencies))))
checkbox_group.callback = CustomJS(args={key:value for key,value in args}, code="""
???
""")
def callback_button_on():
checkbox_group.active = list(range(len(currencies)))
source.data = source_dict
def callback_button_off():
checkbox_group.active = []
source.data = {}
select_all = Button(label='Select all')
select_all.on_click(callback_button_on)
select_none = Button(label='Select none')
select_none.on_click(callback_button_off)
group = column(checkbox_group)
show(row(group, p))
output_file("Daily_Returns.html")
save(p)