Callback functions represent code that is to be executed in the server once an action is triggered from within the User Interface (UI), typically through interaction with a Bokeh widget, such as a Slider, Select box, Button, or TextInput box. Callback functions can be used to modify aspects of the display, modify what data get displayed, or to perform computations with the data based on user interactions.

A central design goal of Bokeh server is to allow developers to write callback functions in Python, rather than in JavaScript, which is the language that web browsers are working with under the covers. This leverages both the broader familiarity of programmers with Python, as well as the rich ecosystem of Python software packages that can be drawn upon in order to carry out custom data processing operations. In some cases, however, it might not be possible to write a suitable callback in Python, and one will instead need to write it in JavaScript directly (to be called from within Python+Bokeh code). Within Bokeh, these custom JavaScript callbacks are referred to as CustomJS code.

In some examples that follow, we will dig a bit more into how callbacks are constructed and called from within Bokeh server applications. While most of the examples we show involve associating callbacks with buttons, selectors, and other widgets in a GUI, it should be noted that callbacks can also be associated with tools that interact directly with plotted data. For example, if you wanted to set a threshold on some data for use in a subsequent computation, you might use Bokeh to plot a histogram of those data values, and implement a TapTool that would enable you to visually inspect the histogram and use your mouse to tap where specifically in the distribution to set that threshold.

 
©  |   Cornell University    |   Center for Advanced Computing    |   Copyright Statement    |   Inclusivity Statement