bokeh.driving

Provide a set of decorators useful for repeatedly updating a a function parameter in a specified way each time the function is called.

These decorators can be especially useful in conjunction with periodic callbacks in a Bokeh server application.

Example

As an example, consider the bounce forcing function, which advances a sequence forwards and backwards:

from bokeh.driving import bounce

@bounce([0, 1, 2])
def update(i):
    print(i)

If this function is repeatedly called, it will print the following sequence on standard out:

0 1 2 2 1 0 0 1 2 2 1 ...
bounce(sequence: Sequence[int]) partial[Callable[[], None]][source]

Return a driver function that can advance a “bounced” sequence of values.

seq = [0, 1, 2, 3]

# bounce(seq) => [0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, ...]
Parameters

sequence (seq) – a sequence of values for the driver to bounce

cosine(w: float, A: float = 1, phi: float = 0, offset: float = 0) partial[Callable[[], None]][source]

Return a driver function that can advance a sequence of cosine values.

value = A * cos(w*i + phi) + offset
Parameters
  • w (float) – a frequency for the cosine driver

  • A (float) – an amplitude for the cosine driver

  • phi (float) – a phase offset to start the cosine driver with

  • offset (float) – a global offset to add to the driver values

count() partial[Callable[[], None]][source]

Return a driver function that can advance a simple count.

force(f: Callable[[Any], None], sequence: Iterator[Any]) Callable[[], None][source]

Return a decorator that can “force” a function with an arbitrary supplied generator

Parameters

sequence (iterable) – generator to drive f with

Returns

decorator

linear(m: float = 1, b: float = 0) partial[Callable[[], None]][source]

Return a driver function that can advance a sequence of linear values.

value = m * i + b
Parameters
  • m (float) – a slope for the linear driver

  • x (float) – an offset for the linear driver

repeat(sequence: Sequence[int]) partial[Callable[[], None]][source]

Return a driver function that can advance a repeated of values.

seq = [0, 1, 2, 3]

# repeat(seq) => [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, ...]
Parameters

sequence (seq) – a sequence of values for the driver to bounce

sine(w: float, A: float = 1, phi: float = 0, offset: float = 0) partial[Callable[[], None]][source]

Return a driver function that can advance a sequence of sine values.

value = A * sin(w*i + phi) + offset
Parameters
  • w (float) – a frequency for the sine driver

  • A (float) – an amplitude for the sine driver

  • phi (float) – a phase offset to start the sine driver with

  • offset (float) – a global offset to add to the driver values