Clientside callback to filter data and update graph

Hi!
Thanks for the answer. It helped a lot to put me in the right direction. I had to use forEach() to define x and y since I store the entire df as JSON (df.to_dict('records')), then it worked.

var x_array = [];
var y_array = [];
var filtered_data = data.filter(d => d["country"] == country);
filtered_data.forEach((arr)=>{x_array.push(arr.year)});
filtered_data.forEach((arr)=>{y_array.push(arr.indicator)});

return {
            'data': [{
                x: x_array,
                y: y_array,
                mode: "markers"
             }]
}

Thanks a lot!

1 Like