Session Ready
Exercise

Learn about widget callbacks

You'll now learn how to use widget callbacks to update the state of a Bokeh application, and in turn, the data that is presented to the user.

Your job in this exercise is to use the slider's on_change() function to update the plot's data from the previous example. NumPy's sin() function will be used to update the y-axis data of the plot.

Now that you have added a widget callback, notice how as you move the slider of your app, the figure also updates!

Instructions
100 XP
  • Define a callback function callback with the parameters attr, old, new.
  • Read the current value of slider as a variable scale. You can do this using slider.value.
  • Compute values for the updated y using np.sin(scale/x).
  • Update source.data with the new data dictionary. The value for 'x' remains the same, but 'y' should be set to the updated value.
  • Attach the callback to the 'value' property of slider. This can be done using on_change() and passing in 'value' and callback.