Hello!
I’m trying to create a bar chart that is updated by option selected in select widget using customJS.
But it is not updating the plot I don’t know why.
This is my code:
import numpy as np
notif = ['Notificacao1', 'Notificacao2', 'Notificacao3', 'Notificacao4',
'Notificacao5', 'Notificacao6', 'Notificacao7', 'Notificacao8', 'Notificacao9',
'Notificacao10', 'Notificacao11', 'Notificacao12', 'Notificacao13',
'Notificacao14', 'Notificacao15', 'Notificacao16', 'Notificacao17',
'Notificacao18', 'Notificacao19', 'Notificacao20', 'Notificacao21',
'Notificacao22', 'Notificacao23', 'Notificacao24', 'Notificacao25',
'Notificacao26', 'Notificacao27', 'Notificacao28', 'Notificacao29',
'Notificacao30']
notif = np.array(notif)
group = [1] * 10 + [2] * 10 + [3] * 10
group = np.array(group)
import pandas as pd
df = pd.DataFrame(dict(notif = notif,group = group))
from bokeh.io import show, output_file
from bokeh.plotting import figure
from bokeh.models import Select,ColumnDataSource, CustomJS
from bokeh.layouts import column
source = ColumnDataSource(data = df)
p = figure(y_range = source.data['notif'][source.data['group'] == 1].tolist())
p.hbar(y = 'notif', source = source, height = .9, right = .1)
select = Select(title = 'Grupo', value = '1', options = ['1','2','3'])
callback = CustomJS(args = dict(source = source, select = select),
code = """ var data = source.data;
var G = int(select.value);
group = data['group']
data['notif'] = data['notif'][group == G]
data['group'] = data['group'][group == G]
source.change.emit()""")
select.js_on_change('value', callback)
layout = column(select, p)
show(layout)