Hi everyone, below is a code snippet I wrote for an interactive pie chart I’m trying to plot.
From my understanding, this code will be triggered when I interact with the object associated with this callback (slider), and this code should update the data in the source_dict depending on the widget value.
Looking at the last couple of lines (last for loop) I’m clearly updating the value in my source_dict however I don’t see this change being reflected in my plot. Can anyone correct any misunderstandings I may have? (specific context in the previous post if interested)
cjs = CustomJS(args=dict(sl=slider, source=source, source_dict=source_dict),code='''
var year = cb_obj.value;
var upd_source = {};
var multiplier = year - 1990;
for (const [k,v] of Object.entries(source_dict)){
upd_source[k] = [];
}
for (const [k,v] of Object.entries(source.data)) {
if (v >= multiplier * 31 && v < multiplier * 32) {
upd_source[k].push(source.data[k][v]);
}
}
// Loops through the source_dict (i.e {"1990": CDS({Disease: [...]...,})})
/* Find whether the year k is the same as the slider value, if so set the CDS data for that year
as the value in upd_source["Disease"/"Deaths"...] (for e.g) */
for (const [k,v] of Object.entries(source_dict)){
if (k == year) {
for (const [a,b] of Object.entries(source.data)) {
v.data = upd_source[a];
}
}
else {
for (let key in v.data) {
v.data[key] = [];
}
}
}
''')