Hello!. First of all I need to say that I am rather new to python and I know nothing of javascript. I am developing a small code with python and I am running it in a bokeh server.

I have a set of data that I expand or diminish with a set of sliders, once I have the final data (not moving the sliders any more) I need to make some calculations, for this I thought I could use a button. The idea will be to select the data with the sliders, then use this ‘new_data’ to make the calculation via the button, so when I press the button the final data goes through a function a this function returns something.

The problem is that when I click the button the “new data” does not get modify and I get a message: error handling message Message ‘PATCH-DOC’ (revision 1): TypeError("‘ColumnDataSource’ object has no attribute ‘**getitem**’",)

I saw https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/eVX31sGGHaI but the links in there goes to ‘404’ pages. I hope someone would explain to me the error I am making, I think it must be some stupid thing but I can not realize what it is.

The (not working) code I am trying to use is:

import numpy as np

import math

from numpy import loadtxt

from bokeh.plotting import figure, output_file, show

from bokeh.layouts import layout, widgetbox,row

from bokeh.models.widgets import Slider, Button

from bokeh.models import ColumnDataSource

from bokeh.io import curdoc

from lmfit.models import GaussianModel

from aju_gauss_test1 import gauss

output_file(‘mecagoenesto’)

data=loadtxt(‘sn1996cb-19961217.dat’)

x0=data[:,0]

x1=np.array(x0).tolist()

y0=data[:,1]

escala=10**(-int(math.log(abs(y0[0]),10)))

y1=np.array(y0*escala).tolist()

def f_n(array,value):

idx=(np.abs(array-value)).argmin()

return array[idx]

lp=f_n(np.array(x1),5937.5)

rp=f_n(np.array(x1),6312.5)

x = x1[x1.index(lp):x1.index(rp)]

y = y1[x1.index(lp):x1.index(rp)]

source=ColumnDataSource(data={‘x’:x, ‘y’:y})

p=figure(title=‘prueba’,x_axis_label=‘lambda’,y_axis_label=‘flujo’)

p.line(x=‘x’,y=‘y’,source=source,color=‘blue’,legend=‘linea’)

def update_x(attr,old,new):

```
# Read the current value of the slider: scale
sv1 = slider1.value
sv2= slider2.value
new_x_azul=f_n(np.array(x1),sv1)
new_x_rojo=f_n(np.array(x1),sv2)
# Update source with the new data values
slider_new_data = {
'x':x1[x1.index(new_x_azul):x1.index(new_x_rojo)],
'y':y1[x1.index(new_x_azul):x1.index(new_x_rojo)]
}
source.data=slider_new_data
```

source_gauss=ColumnDataSource(data={‘x’:source.data[‘x’],‘y’:source.data[‘y’]}) #This is a data I need to use for the calculations

def update():

button_new_data={

‘x’:source_gauss[‘x’],

‘y’:source_gauss[‘y’]

}

```
source_gauss.data=button_new_data
```

#I want to pass this values to a function but they are empty or something

x_for_gauss=source_gauss.data[‘x’]

y_for_gauss=source_gauss.data[‘y’]

slider1=Slider(start=5750,end=6125,value=5937.5,step=0.1,title=‘azul’)

slider2=Slider(start=6125,end=6500,value=6312.5,step=0.1,title=‘rojo’)

slider1.on_change(‘value’,update_x)

slider2.on_change(‘value’,update_x)

button=Button(label=‘Make Adjustment’)

button.on_click(update)

inputs = widgetbox(slider1,slider2,button,sizing_mode = ‘fixed’)

l = layout([

[inputs, p],

], sizing_mode=‘fixed’)

curdoc().add_root(l)

curdoc().title = “pruebas”

``

``