Anaconda Enterprise: Documentation

# 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 accomplished by passing an event class, and a callback function to the 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 `bokeh.events.``ButtonClick`(model)

  Announce a button click event on a Bokeh Button widget.

class `bokeh.events.``DoubleTap`(model, sx=None, sy=None, x=None, y=None)

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

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

class `bokeh.events.``Event`(model)

  Base class for all Bokeh events.

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

  classmethod `decode_json`(dct)

    Custom JSON decoder for Events.

    Can be used as the `object_hook` argument of `json.load` or `json.loads`.

    Parameters: | dct (dict) – a JSON dictionary to decode The dictionary should have keys `event_name` and `event_values`
    Raises: | ValueError, if the event_name is unknown

    Examples

        >>> import json
        >>> from bokeh.events import Event
        >>> data = '{"event_name": "pan", "event_values" : {"model_id": 1, "x": 10, "y": 20, "sx": 200, "sy": 37}}'
        >>> json.loads(data, object_hook=Event.decode_json)
        <bokeh.events.Pan object at 0x1040f84a8>

class `bokeh.events.``LODEnd`(model)

  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 `bokeh.events.``LODStart`(model)

  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 `bokeh.events.``MouseEnter`(model, sx=None, sy=None, x=None, y=None)

  Announce a mouse enter event onto a Bokeh plot.

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

  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 `bokeh.events.``MouseLeave`(model, sx=None, sy=None, x=None, y=None)

  Announce a mouse leave event from a Bokeh plot.

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

  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 `bokeh.events.``MouseMove`(model, sx=None, sy=None, x=None, y=None)

  Announce a mouse movement event over a Bokeh plot.

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

  Note

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

class `bokeh.events.``MouseWheel`(model, delta=None, **kwargs)

  Announce a mouse wheel event on a Bokeh plot.

  `delta`

    float – the (signed) scroll speed

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

  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 `bokeh.events.``Pan`(model, delta_x=None, delta_y=None, direction=None, **kwargs)

  Announce a pan event on a Bokeh plot.

  `delta_x`

    float – the amount of scroll in the x direction

  `delta_y`

    float – the amount of scroll in the y direction

  `direction`

    float – the direction of scroll (1 or -1)

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

class `bokeh.events.``PanEnd`(model, sx=None, sy=None, x=None, y=None)

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

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

class `bokeh.events.``PanStart`(model, sx=None, sy=None, x=None, y=None)

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

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

class `bokeh.events.``Pinch`(model, scale=None, **kwargs)

  Announce a pinch event on a Bokeh plot.

  `scale`

    float – the (signed) amount of scaling

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

  Note

  This event is only applicable for touch-enabled devices.

class `bokeh.events.``PinchEnd`(model, sx=None, sy=None, x=None, y=None)

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

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

  Note

  This event is only applicable for touch-enabled devices.

class `bokeh.events.``PinchStart`(model, sx=None, sy=None, x=None, y=None)

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

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

  Note

  This event is only applicable for touch-enabled devices.

class `bokeh.events.``PlotEvent`(model)

  PlotEvent is the base class for all events applicable to Plot models.

class `bokeh.events.``PointEvent`(model, sx=None, sy=None, x=None, y=None)

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

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

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

class `bokeh.events.``Press`(model, sx=None, sy=None, x=None, y=None)

  Announce a press event on a Bokeh plot.

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space

class `bokeh.events.``Reset`(model)

  Announce a button click event on a plot ResetTool.

class `bokeh.events.``SelectionGeometry`(model, geometry=None, final=True)

  Announce the coordinates of a selection event on a plot.

  `geometry`

    dict – a dictionary containing the coordinates of the selection event.

  `final`

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

class `bokeh.events.``Tap`(model, sx=None, sy=None, x=None, y=None)

  Announce a tap or click event on a Bokeh plot.

  `sx`

    float – x-coordinate of the event in screen space

  `sx`

    float – y-coordinate of the event in screen space

  `x`

    float – x-coordinate of the event in data space

  `y`

    float – y-coordinate of the event in data space