bokeh.events#

Represent granular events that can be used to trigger callbacks.

Bokeh documents and applications are capable of supporting various kinds of interactions. These are often associated with events, such as mouse or touch events, interactive downsampling mode activation, widget or tool events, and others. The classes in this module represent these different events, so that callbacks can be attached and executed when they occur.

It is possible to respond to events with CustomJS callbacks, which will function with or without a Bokeh server. This can be accomplished by passing and event class, and a CustomJS model to the js_on_event() method. When the CustomJS is executed in the browser, its cb_obj argument will contain the concrete event object that triggered the callback.

from bokeh.events import ButtonClick
from bokeh.models import Button, CustomJS

button = Button()

button.js_on_event(ButtonClick, CustomJS(code='console.log("JS:Click")'))

Alternatively it is possible to trigger Python code to run when events happen, in the context of a Bokeh application running on a Bokeh server. This can be accomplished by passing an event class, and a callback function to the on_event() method. The callback should accept a single argument event, which will be passed the concrete event object that triggered the callback.

from bokeh.events import ButtonClick
from bokeh.models import Button

button = Button()

def callback(event):
    print('Python:Click')

button.on_event(ButtonClick, callback)

Note

There is no throttling of events. Some events such as MouseMove may trigger at a very high rate.

class ButtonClick(model: AbstractButton | None)[source]#

Announce a button click event on a Bokeh button widget.

class ConnectionLost[source]#

Announce when a connection to the server/client was lost.

Note

To register a JS callback for this event in standalone embedding mode, one has to either use curdoc() or an explicit Document instance, e.g.:

from bokeh.io import curdoc
curdoc().js_on_event("document_ready", handler)
class DocumentEvent[source]#

Base class for all Bokeh Document events.

This base class is not typically useful to instantiate on its own.

class DocumentReady[source]#

Announce when a Document is fully idle.

Note

To register a JS callback for this event in standalone embedding mode, one has to either use curdoc() or an explicit Document instance, e.g.:

from bokeh.io import curdoc
curdoc().js_on_event("document_ready", handler)
class DoubleTap(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce a double-tap or double-click event on a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

class Event[source]#

Base class for all Bokeh events.

This base class is not typically useful to instantiate on its own.

to_serializable(serializer: Serializer) BokehEventRep[source]#

Converts this object to a serializable representation.

class LODEnd(model: Plot | None)[source]#

Announce the end of “interactive level-of-detail” mode on a plot.

During interactive actions such as panning or zooming, Bokeh can optionally, temporarily draw a reduced set of the data, in order to maintain high interactive rates. This is referred to as interactive Level-of-Detail (LOD) mode. This event fires whenever a LOD mode has just ended.

class LODStart(model: Plot | None)[source]#

Announce the start of “interactive level-of-detail” mode on a plot.

During interactive actions such as panning or zooming, Bokeh can optionally, temporarily draw a reduced set of the data, in order to maintain high interactive rates. This is referred to as interactive Level-of-Detail (LOD) mode. This event fires whenever a LOD mode has just begun.

class LegendItemClick(model: Legend, item: LegendItem)[source]#

Announce a click event on a Bokeh legend item.

class MenuItemClick(model: Model, item: str | None = None)[source]#

Announce a button click event on a Bokeh menu item.

class ModelEvent(model: Model | None)[source]#

Base class for all Bokeh Model events.

This base class is not typically useful to instantiate on its own.

__init__(model: Model | None) None[source]#

Create a new base event.

Parameters:

model (Model) – a Bokeh model to register event callbacks on

class MouseEnter(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce a mouse enter event onto a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

Note

The enter event is generated when the mouse leaves the entire Plot canvas, including any border padding and space for axes or legends.

class MouseLeave(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce a mouse leave event from a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

Note

The leave event is generated when the mouse leaves the entire Plot canvas, including any border padding and space for axes or legends.

class MouseMove(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce a mouse movement event over a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

Note

This event can fire at a very high rate, potentially increasing network traffic or CPU load.

class MouseWheel(model: Plot | None, *, delta: float | None = None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce a mouse wheel event on a Bokeh plot.

delta#

the (signed) scroll speed

Type:

float

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

Note

By default, Bokeh plots do not prevent default scroll events unless a WheelZoomTool or WheelPanTool is active. This may change in future releases.

class Pan(model: Plot | None, *, delta_x: float | None = None, delta_y: float | None = None, direction: Literal[-1, -1] | None = None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce a pan event on a Bokeh plot.

delta_x#

the amount of scroll in the x direction

Type:

float

delta_y#

the amount of scroll in the y direction

Type:

float

direction#

the direction of scroll (1 or -1)

Type:

float

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

class PanEnd(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce the end of a pan event on a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

class PanStart(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce the start of a pan event on a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

class Pinch(model: Plot | None, *, scale: float | None = None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce a pinch event on a Bokeh plot.

scale#

the (signed) amount of scaling

Type:

float

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

Note

This event is only applicable for touch-enabled devices.

class PinchEnd(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce the end of a pinch event on a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

Note

This event is only applicable for touch-enabled devices.

class PinchStart(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce the start of a pinch event on a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

Note

This event is only applicable for touch-enabled devices.

class PlotEvent(model: Plot | None)[source]#

The base class for all events applicable to Plot models.

class PointEvent(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Base class for UI events associated with a specific (x,y) point.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

Note that data space coordinates are relative to the default range, not any extra ranges, and the screen space origin is at the top left of the HTML canvas.

class Press(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce a press event on a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

class PressUp(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce a pressup event on a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

class RangesUpdate(model: Plot | None, *, x0: float | None = None, x1: float | None = None, y0: float | None = None, y1: float | None = None)[source]#

Announce combined range updates in a single event.

x0#

start x-coordinate for the default x-range

Type:

float

x1#

end x-coordinate for the default x-range

Type:

float

y0#

start x-coordinate for the default y-range

Type:

float

y1#

end y-coordinate for the default x-range

Type:

float

Callbacks may be added to range start and end properties to respond to range changes, but this can result in multiple callbacks being invoked for a single logical operation (e.g. a pan or zoom). This event is emitted by supported tools when the entire range update is complete, in order to afford a single event that can be responded to.

class Reset(model: Plot | None)[source]#

Announce a button click event on a plot ResetTool.

class Rotate(model: Plot | None, *, rotation: float | None = None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce a rotate event on a Bokeh plot.

rotation#

the rotation that has been done (in deg)

Type:

float

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

Note

This event is only applicable for touch-enabled devices.

class RotateEnd(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce the end of a rotate event on a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

Note

This event is only applicable for touch-enabled devices.

class RotateStart(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce the start of a rotate event on a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

Note

This event is only applicable for touch-enabled devices.

class SelectionGeometry(model: Plot | None, geometry: GeometryData | None = None, final: bool = True)[source]#

Announce the coordinates of a selection event on a plot.

geometry#

a dictionary containing the coordinates of the selection event.

Type:

dict

final#

whether the selection event is the last selection event in the case of selections on every mousemove.

Type:

bool

class Tap(model: Plot | None, sx: float | None = None, sy: float | None = None, x: float | None = None, y: float | None = None, modifiers: KeyModifiers | None = None)[source]#

Announce a tap or click event on a Bokeh plot.

sx#

x-coordinate of the event in screen space

Type:

float

sy#

y-coordinate of the event in screen space

Type:

float

x#

x-coordinate of the event in data space

Type:

float

y#

y-coordinate of the event in data space

Type:

float

class ValueSubmit(model: TextInput | None, value: str)[source]#

Announce a value being submitted on a text input widget.