Reputation: 255
The purpose of the below code is to generate TextInput()
boxes based on an input in a TextInput()
box and extract values from the new TextInput()
boxes
The problem is that I am having difficulty understanding the on_change()
function. After typing into the first box I get a number of boxes (which I will call 'generated box').
I am able to print 'Printing' whenever I type into a generated box so I know that the on_change()
method is working in a loop for all the generated boxes but I have been unable to extract the User input in any of the generated boxes.
from bokeh.client import push_session
from bokeh.io import curdoc
from bokeh.models import ColumnDataSource, TextInput
from bokeh.layouts import gridplot, row, column
curdoc().clear()
NR=TextInput() #Input no. of rows in this
N=[] #stores the TextInput boxes NR times
value=0
def PushSes(x):
rowe = row(x)
curdoc().add_root(rowe)
def update(attr,new,old):
global value
global N
value1= int(NR.value)
for i in range (value1):
N.append(TextInput()) #N stores the TextInput boxes
for i in N:
i.on_change('value',update1)
curdoc().clear()
PushSes(N)
def update1(attr,new,old):
print('Printing')
NR.on_change('value',update)
val=[] #stores value from the first row
session=push_session(curdoc())
PushSes(NR)
session.show()
session.loop_until_closed()
Upvotes: 2
Views: 6176
Reputation: 255
Solved the problem -
def update1(attr,new,old):
print('Printing')
print(old)
In a loop old
has the values and prints in order of the typing. Thanks to @bigreddot for the hint.
Upvotes: 2
Reputation: 34568
The new
parameter passed to update1
by Bokeh when it calls the callback, has the new value of the text box.
Upvotes: 1