Skip to content

Instantly share code, notes, and snippets.

@npyoung
Created January 20, 2017 03:22
Show Gist options
  • Save npyoung/05fe971dff89353b4b627b0fe0f64917 to your computer and use it in GitHub Desktop.
Save npyoung/05fe971dff89353b4b627b0fe0f64917 to your computer and use it in GitHub Desktop.
Bokeh server app for adjusting a data range with a slider
from bokeh.layouts import widgetbox, column
from bokeh.models.widgets import RangeSlider
from bokeh.models.ranges import Range
from bokeh.plotting import figure, curdoc
range_slider = RangeSlider(start=0, end=10, range=(1,9), step=.1, title="Stuff")
p = figure(x_range=range_slider.range)
p.line(x=range(10), y=[x**2 for x in range(10)])
def update_range(attr, new, old):
p.x_range.start = new[0]
p.x_range.end = new[1]
range_slider.on_change('range', update_range)
curdoc().add_root(column(p, widgetbox(range_slider)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment