bokeh.models.expressions

Represent array expressions to be computed on the client (browser) side by BokehJS.

Expression models are useful as DataSpec values when it is desired that the array values be computed in the browser:

p.circle(x={'expr': some_expression}, ...)

or using the expr convenience function:

from bokeh.core.properties import expr

p.circle(x=expr(some_expression), ...)

In this case, the values of the x coordinates will be computed in the browser by the JavaScript implementation of some_expression using a ColumnDataSource as input.

class CumSum(**kwargs)[source]

Bases: bokeh.models.expressions.Expression

An expression for generating arrays by cumulatively summing a single column from a ColumnDataSource.

field

property type: String

The name of a ColumnDataSource column to cumulatively sum for new values.

include_zero

property type: Bool

Whether to include zero at the start of the result. Note that the length of the result is always the same as the input column. Therefore if this property is True, then the last value of the column will not be included in the sum.

source = ColumnDataSource(data=dict(foo=[1, 2, 3, 4]))

CumSum(field='foo')
# -> [1, 3, 6, 10]

CumSum(field='foo', include_zero=True)
# -> [0, 1, 3, 6]
JSON Prototype
{
  "field": null,
  "id": "40efba9e-4e6f-4c8b-b3e4-c7aff4777f3a",
  "include_zero": false,
  "js_event_callbacks": {},
  "js_property_callbacks": {},
  "name": null,
  "subscribed_events": [],
  "tags": []
}
class Expression(**kwargs)[source]

Bases: bokeh.model.Model

Base class for Expression models that represent a computation to be carried out on the client-side.

JavaScript implementations should implement the following methods:

Note

If you wish for results to be cached per source, and updated only if the source changes, implement _v_compute: (souce) instead.

Note

This is an abstract base class used to help organize the hierarchy of Bokeh model types. It is not useful to instantiate on its own.

JSON Prototype
{
  "id": "b188c347-a721-4392-b81a-8e6fbf0d8aae",
  "js_event_callbacks": {},
  "js_property_callbacks": {},
  "name": null,
  "subscribed_events": [],
  "tags": []
}
class Stack(**kwargs)[source]

Bases: bokeh.models.expressions.Expression

An expression for generating arrays by summing different columns from a ColumnDataSource.

This expression is useful for implementing stacked bar charts at a low level.

fields

property type: Seq ( String )

A sequence of fields from a ColumnDataSource to sum (elementwise). For example:

Stack(fields=['sales', 'marketing'])

Will compute an array of values (in the browser) by adding the elements of the 'sales' and 'marketing' columns of a data source.

JSON Prototype
{
  "fields": [],
  "id": "d0d27b47-fa66-412b-a445-347fa94ec14f",
  "js_event_callbacks": {},
  "js_property_callbacks": {},
  "name": null,
  "subscribed_events": [],
  "tags": []
}