Oh man, I had typed a long response questioning the use of the DataRange1d model and found the answer along the way
Trick is to assign a DataRange1d, NOT a Range1d model to the extra_y_ranges. I did not understand that that was even possible (is that even documented anywhere/is it in examples?)! Then, create your renderers and tell the renderers what axis to plot on, THEN you assign the renderers back to the DataRange1d object to tell it what to “follow”.
Check it out:
from bokeh.layouts import layout
from bokeh.plotting import figure, show, save
from bokeh.models import Scatter, Rect, ColumnDataSource, Range1d, LinearAxis, DataRange1d, Slider,CustomJS
sdict = {0:{'x':[1,2,3],'y':[1,2,3]}
,1:{'x':[1,2,3],'y':[2,3,4]}
,2:{'x':[1,2,3],'y':[3,4,5]}}
rdict = {0:{'x':[1,2,3],'y':[100,200,300]}
,1:{'x':[1,2,3],'y':[1000,2000,3000]}
,2:{'x':[1,2,3],'y':[3000,4000,5000]}}
s_src = ColumnDataSource(sdict[0])
r_src = ColumnDataSource(rdict[0])
f = figure()
#create the second axis with an empty DataRange1d
f.extra_y_ranges={'r':DataRange1d()}
f.add_layout(LinearAxis(y_range_name='r'),'right')
#first axis renderer
sg = Scatter(x='x',y='y')
sr = f.add_glyph(s_src,sg)
#Tell the primary y_range to "follow" the sr renderer only
f.y_range.renderers=[sr]
#second axis renderer, and tell it to plot on the 'r' y_range_name
rg = Rect(x='x',y='y',height=10,width=0.5)
rr = f.add_glyph(r_src,rg,y_range_name='r')
#THEN, now that that renderer is instantiated, tell the y_range['r'] to follow it
f.extra_y_ranges['r'].renderers=[rr]
#simple slider example to move the plotted data ranges around on both renderers
sl = Slider(start=0,end=len(sdict.keys())-1,value=0)
cb = CustomJS(args=dict(s_src=s_src,sdict=sdict
,r_src=r_src,rdict=rdict
,sl=sl)
,code='''
s_src.data = sdict[sl.value]
r_src.data = rdict[sl.value]
s_src.change.emit()
r_src.change.emit()
''')
sl.js_on_change('value', cb)
lo = layout([f,sl])
save(lo,'dummy.html')
It totally works. LOVE IT.
Last piece still unanswered: Is there a way to wheelzoom in on one y axis without that zoom applying to the other y axis (i.e. control them one at a time). Need a way to “delink” the two from each other…
Thanks so much for the tips/clues, it helps so much.