Updating barplots with callback-function

Hi

Im currently trying to plot the age distribution of a country with an hbar-plot (100 bars, for ages 0 - 100, length depending on size of said agegroup).

The graph should change depending on the value of a slider element, which indicates the year the agedistribution was recorded in:

slider = Slider(start=0, end=99, value=1, step=1, title="Year",
 callback=CustomJS.from_py_func(callback))

The datasource currently looks like this:

m_source = ColumnDataSource(data=dict(y=y_data, right=age_data_m[-1], right2=age_data_m[0]))

Where age_data_m is a 2dimensional numpy array and age_data_m[0] would look like this:

[530, 543, 570, … … , 200, 120 , 20 ,0 ]

the callback definition looks like this:

def callback(source=m_source, window=None):

My current problem is the limitation of ColumnDataSource : Every column needs to be the same length.

The m_source showed above is contains the agedata for 2 years (the last array of age_data_m and the first one).

Since the recorded data spans about 100 years, id have to declare 100 elements in the data-dict of m_source (age_data_m[0], age_data_m[1], age_data_m[2] ...) .

Id like to pass the 2dimensional array age_data_m to the callbackfunction, but then the automatic (on change of the slidervalue) update via

source.trigger('change')

won’t work.

Any advice on this?