I am trying to convey a large amount of scientific data seamlessly with the help of sliders.
Suppose I have 1.png and 2.png in my folder.
from bokeh.io import vform
from bokeh.models import CustomJS, ColumnDataSource, Slider
from bokeh.plotting import Figure, output_file, show
source = ColumnDataSource(data=dict(url=['1.png']))
p = Figure(x_range=(0,1), y_range=(0,1))
callbackimg = CustomJS(args=dict(source=source), code="""
var data = source.get('data');
var f = cb_obj.get('value')
old = data['url']
p.image_url('url',source=source, x=0, y=1,w=1,h=1)
slider = Slider(start=1, end=2, value=1, step=1, title="image number", callback=callbackimg)
layout = vform(slider, p)
The problem is this:
url = data['url'] url.replace("1","f")
replace method returns a new string (which you immediately discard), so you are not actually changing anything in the column data source. You need something like:
old = data['url'] data['url'] = old.replace("1","f")