bokeh.models.DataTable#
- class DataTable(*args: Any, id: ID | None = None, **kwargs: Any)[source]#
Bases:
TableWidgetTwo-dimensional grid for visualization and editing large amounts of data.
Properties#
- align = 'auto'#
- Type:
The alignment point within the parent container.
This property is useful only if this component is a child element of a layout (e.g. a grid). Self alignment can be overridden by the parent container (e.g. grid track align).
- aspect_ratio = None#
-
Describes the proportional relationship between component’s width and height.
This works if any of component’s dimensions are flexible in size. If set to a number,
width / height = aspect_ratiorelationship will be maintained. Otherwise, if set to"auto", component’s preferred width and height will be used to determine the aspect (if not set, no aspect will be preserved).
- auto_edit = False#
- Type:
When enabled editing mode is enabled after a single click on a table cell.
- autosize_mode = 'force_fit'#
- Type:
Describes the column autosizing mode with one of the following options:
"fit_columns"Compute column widths based on cell contents but ensure the table fits into the available viewport. A horizontal scrollbar may appear to ensure readability of contents in all rows.
"fit_viewport"Adjust the viewport size after computing columns widths based on cell contents.
"force_fit"Fit columns into available space dividing the table width across the columns equally (equivalent to fit_columns=True). This results in no horizontal scrollbar showing up, but data can get unreadable if there is not enough space available.
"ignore_viewport"Similarly to
"fit_columns", the column widths are computed based on the cell contents. However, the viewport width is ignored, so that if the columns are smaller than the viewport, there is empty space at the right, or if the columns are larger than the viewport, there is a scrollbar."none"Do not automatically compute column widths.
- Type:
A menu to display when user right clicks on the component.
If set to
"auto", the component may provide a dynamically generated menu. For example,Plotand related models provide aToolMenuinstance for easy access to their tools.Note
Use shift key when right clicking to display the native context menu.
- css_variables = {}#
-
Allows to define dynamically computed CSS variables.
This can be used, for example, to coordinate positioning and styling between canvas’ renderers and/or visuals and HTML-based UI elements.
Variables defined here are equivalent to setting the same variables under
:host { ... }in a CSS stylesheet.Note
This property is experimental and may change at any point.
- disabled = False#
- Type:
Whether the widget will be disabled when rendered.
If
True, the widget will be greyed-out and not responsive to UI events.
- editable = False#
- Type:
Allows to edit table’s contents. Needs cell editors to be configured on columns that are required to be editable.
- elements = []#
- Type:
A collection of DOM-based UI elements attached to this pane.
This can include floating elements like tooltips, allowing to establish a parent-child relationship between this and other UI elements.
- fit_columns = None#
-
This is a legacy parameter. For new development, use the
autosize_modeparameter.Whether columns should be fit to the available width. This results in no horizontal scrollbar showing up, but data can get unreadable if there is not enough space available. If set to True, each column’s width is understood as maximum width.
- flow_mode = 'block'#
-
Defines whether the layout will flow in the
blockorinlinedimension.
- frozen_columns = None#
-
Integer indicating the number of columns to freeze. If set the first N columns will be frozen which prevents them from scrolling out of frame.
- frozen_rows = None#
-
Integer indicating the number of rows to freeze. If set the first N rows will be frozen which prevents them from scrolling out of frame, if set to a negative value last N rows will be frozen.
- header_row = True#
- Type:
Whether to show a header row with column names at the top of the table.
- height = 400#
- Type:
The height of the component (in pixels).
This can be either fixed or preferred height, depending on height sizing policy.
- height_policy = 'auto'#
- Type:
Describes how the component should maintain its height.
"auto"Use component’s preferred sizing policy.
"fixed"Use exactly
heightpixels. Component will overflow if it can’t fit in the available vertical space."fit"Use component’s preferred height (if set) and allow to fit into the available vertical space within the minimum and maximum height bounds (if set). Component’s height neither will be aggressively minimized nor maximized.
"min"Use as little vertical space as possible, not less than the minimum height (if set). The starting point is the preferred height (if set). The height of the component may shrink or grow depending on the parent layout, aspect management and other factors.
"max"Use as much vertical space as possible, not more than the maximum height (if set). The starting point is the preferred height (if set). The height of the component may shrink or grow depending on the parent layout, aspect management and other factors.
Note
This is an experimental feature and may change in future. Use it at your own discretion. Prefer using
sizing_modeif this level of control isn’t strictly necessary.
- html_attributes = {}#
-
Allows to configure HTML attributes on the underlying HTML element.
- html_id = None#
-
Sets the
idattribute of the underlying HTML element.This is a shorthand for the common HTML
idattribute. Alternatively theidcan be set in thehtml_attributesdictionary.html_idtakes precedence.
- index_header = '#'#
- Type:
The column header to display for the index column, if it is present.
- index_position = 0#
-
Where among the list of columns to insert a column displaying the row index. Negative indices are supported, and specify an index position from the end of the list of columns (i.e. standard Python behaviour).
To prevent the index column from being added, set to None.
If the absolute value of index_position is larger than the length of the columns, then the index will appear at the beginning or end, depending on the sign.
- margin = 5#
- Type:
Allows to create additional space around the component. The values in the tuple are ordered as follows - Margin-Top, Margin-Right, Margin-Bottom and Margin-Left, similar to CSS standards. Negative margin values may be used to shrink the space from any direction.
- max_height = None#
- Type:
Maximal height of the component (in pixels) if height is adjustable.
- max_width = None#
- Type:
Maximal width of the component (in pixels) if width is adjustable.
- min_height = None#
- Type:
Minimal height of the component (in pixels) if height is adjustable.
- min_width = None#
- Type:
Minimal width of the component (in pixels) if width is adjustable.
- name = None#
-
An arbitrary, user-supplied name for this model.
This name can be useful when querying the document to retrieve specific Bokeh models.
>>> plot.scatter([1,2,3], [4,5,6], name="temp") >>> plot.select(name="temp") [GlyphRenderer(id='399d53f5-73e9-44d9-9527-544b761c7705', ...)]
Note
No uniqueness guarantees or other conditions are enforced on any names that are provided, nor is the name used directly by Bokeh for any reason.
- reorderable = True#
- Type:
Allows the reordering of a table’s columns. To reorder a column, click and drag a table’s header to the desired location in the table. The columns on either side will remain in their previous order.
- resizable = False#
- Type:
Either(Bool,Enum(Dimensions))
Whether the layout is interactively resizable, and if so in which dimensions.
- scroll_to_selection = True#
- Type:
Whenever a selection is made on the data source, scroll the selected rows into the table’s viewport if none of the selected rows are already in the viewport.
- selectable = True#
-
Whether a table’s rows can be selected or not. Using
checkboxis equivalent to True, but makes selection visible through a checkbox for each row, instead of highlighting rows. Multiple selection is allowed and can be achieved by either clicking multiple checkboxes (if enabled) or using Shift + click on rows.
- sizing_mode = None#
- Type:
How the component should size itself.
This is a high-level setting for maintaining width and height of the component. To gain more fine grained control over sizing, use
width_policy,height_policyandaspect_ratioinstead (those take precedence oversizing_mode).Possible scenarios:
"inherit"The sizing mode is inherited from the parent layout. If there is no parent layout (or parent is not a layout), then this value is treated as if no value for
sizing_modewas provided."fixed"Component is not responsive. It will retain its original width and height regardless of any subsequent browser window resize events.
"stretch_width"Component will responsively resize to stretch to the available width, without maintaining any aspect ratio. The height of the component depends on the type of the component and may be fixed or fit to component’s contents.
"stretch_height"Component will responsively resize to stretch to the available height, without maintaining any aspect ratio. The width of the component depends on the type of the component and may be fixed or fit to component’s contents.
"stretch_both"Component is completely responsive, independently in width and height, and will occupy all the available horizontal and vertical space, even if this changes the aspect ratio of the component.
"scale_width"Component will responsively resize to stretch to the available width, while maintaining the original or provided aspect ratio.
"scale_height"Component will responsively resize to stretch to the available height, while maintaining the original or provided aspect ratio.
"scale_both"Component will responsively resize to both the available width and height, while maintaining the original or provided aspect ratio.
- sortable = True#
- Type:
Allows to sort table’s contents. By default natural order is preserved. To sort a column, click on it’s header. Clicking one more time changes sort direction. Use Ctrl + click to return to natural order. Use Shift + click to sort multiple columns simultaneously.
- source = ColumnDataSource(id='p58736', ...)#
- Type:
The source of data for the widget.
- styles = {}#
- Type:
Inline CSS styles applied to the underlying DOM element.
- stylesheets = []#
- Type:
Additional style-sheets to use for the underlying DOM element.
Note that all bokeh’s components use shadow DOM, thus any included style sheets must reflect that, e.g. use
:hostCSS pseudo selector to access the root DOM element.
- syncable = True#
- Type:
Indicates whether this model should be synchronized back to a Bokeh server when updated in a web browser. Setting to
Falsemay be useful to reduce network traffic when dealing with frequently updated objects whose updated values we don’t need.Note
Setting this property to
Falsewill prevent anyon_change()callbacks on this object from triggering. However, any JS-side callbacks will still work.
- tags = []#
- Type:
An optional list of arbitrary, user-supplied values to attach to this model.
This data can be useful when querying the document to retrieve specific Bokeh models:
>>> r = plot.scatter([1,2,3], [4,5,6]) >>> r.tags = ["foo", 10] >>> plot.select(tags=['foo', 10]) [GlyphRenderer(id='1de4c3df-a83d-480a-899b-fb263d3d5dd9', ...)]
Or simply a convenient way to attach any necessary metadata to a model that can be accessed by
CustomJScallbacks, etc.Note
No uniqueness guarantees or other conditions are enforced on any tags that are provided, nor are the tags used directly by Bokeh for any reason.
- view = CDSView(id='p58739', ...)#
-
A view into the data source to use when rendering table rows. A default view of the entire data source is created if a view is not passed in during initialization.
- width = 600#
- Type:
The width of the component (in pixels).
This can be either fixed or preferred width, depending on width sizing policy.
- width_policy = 'auto'#
- Type:
Describes how the component should maintain its width.
"auto"Use component’s preferred sizing policy.
"fixed"Use exactly
widthpixels. Component will overflow if it can’t fit in the available horizontal space."fit"Use component’s preferred width (if set) and allow it to fit into the available horizontal space within the minimum and maximum width bounds (if set). Component’s width neither will be aggressively minimized nor maximized.
"min"Use as little horizontal space as possible, not less than the minimum width (if set). The starting point is the preferred width (if set). The width of the component may shrink or grow depending on the parent layout, aspect management and other factors.
"max"Use as much horizontal space as possible, not more than the maximum width (if set). The starting point is the preferred width (if set). The width of the component may shrink or grow depending on the parent layout, aspect management and other factors.
Note
This is an experimental feature and may change in future. Use it at your own discretion. Prefer using
sizing_modeif this level of control isn’t strictly necessary.
Methods#
- apply_theme(property_values: dict[str, Any]) None#
Apply a set of theme values which will be used rather than defaults, but will not override application-set values.
The passed-in dictionary may be kept around as-is and shared with other instances to save memory (so neither the caller nor the
HasPropsinstance should modify it).- Parameters:
property_values (dict) – theme values to use in place of defaults
- Returns:
None
- classmethod clear_extensions() None#
Clear any currently defined custom extensions.
Serialization calls will result in any currently defined custom extensions being included with the generated Document, whether or not there are utilized. This method can be used to clear out all existing custom extension definitions.
- clone(**overrides: Any) Self#
Duplicate a
HasPropsobject.This creates a shallow clone of the original model, i.e. any mutable containers or child models will not be duplicated. Allows to override particular properties while cloning.
- classmethod dataspecs() dict[str, DataSpec]#
Collect the names of all
DataSpecproperties on this class.This method always traverses the class hierarchy and includes properties defined on any parent classes.
- classmethod descriptors() list[PropertyDescriptor[Any]]#
List of property descriptors in the order of definition.
- equals(other: HasProps) bool#
Structural equality of models.
- Parameters:
other (HasProps) – the other instance to compare to
- Returns:
True, if properties are structurally equal, otherwise False
- static from_data(data, columns=None, formatters={}, **kwargs) DataTable[source]#
Create a simple table from a pandas dataframe, dictionary or ColumnDataSource.
- Parameters:
data (DataFrame or dict or ColumnDataSource) – The data to create the table from. If the data is a dataframe or dictionary, a ColumnDataSource will be created from it.
columns (list, optional) – A list of column names to use from the input data. If None, use all columns. (default: None)
formatters (dict, optional) – A mapping of column names and corresponding Formatters to apply to each column. (default: None)
- Keyword Arguments:
DataTable. (Any additional keyword arguments will be passed to)
- Returns:
DataTable
- Raises:
ValueError – If the provided data is not a ColumnDataSource or a data source that a ColumnDataSource can be created from.
- js_link(attr: str, other: Model, other_attr: str, attr_selector: int | str | None = None) None#
Link two Bokeh model properties using JavaScript.
This is a convenience method that simplifies adding a
CustomJScallback to update one Bokeh model property whenever another changes value.- Parameters:
Added in version 1.1
- Raises:
Examples
This code with
js_link:select.js_link('value', plot, 'sizing_mode')
is equivalent to the following:
from bokeh.models import CustomJS select.js_on_change('value', CustomJS(args=dict(other=plot), code="other.sizing_mode = this.value" ) )
Additionally, to use attr_selector to attach the left side of a range slider to a plot’s x_range:
range_slider.js_link('value', plot.x_range, 'start', attr_selector=0)
which is equivalent to:
from bokeh.models import CustomJS range_slider.js_on_change('value', CustomJS(args=dict(other=plot.x_range), code="other.start = this.value[0]" ) )
- js_on_change(event: str, *callbacks: JSChangeCallback) None#
Attach a
CustomJScallback to an arbitrary BokehJS model event.On the BokehJS side, change events for model properties have the form
"change:property_name". As a convenience, if the event name passed to this method is also the name of a property on the model, then it will be prefixed with"change:"automatically:# these two are equivalent source.js_on_change('data', callback) source.js_on_change('change:data', callback)
However, there are other kinds of events that can be useful to respond to, in addition to property change events. For example to run a callback whenever data is streamed to a
ColumnDataSource, use the"stream"event on the source:source.js_on_change('streaming', callback)
- classmethod lookup(name: str, *, raises: bool = True) PropertyDescriptor[Any] | None#
Find the
PropertyDescriptorfor a Bokeh property on a class, given the property name.- Parameters:
- Returns:
descriptor for property named
name- Return type:
- on_change(attr: str, *callbacks: PropertyCallback) None#
Add a callback on this object to trigger when
attrchanges.- Parameters:
attr (str) – an attribute name on this object
*callbacks (callable) – callback functions to register
- Returns:
None
Examples
widget.on_change('value', callback1, callback2, ..., callback_n)
- on_event(event: str | type[Event], *callbacks: EventCallback) None#
Run callbacks when the specified event occurs on this Model
Not all Events are supported for all Models. See specific Events in bokeh.events for more information on which Models are able to trigger them.
- classmethod parameters() list[Parameter]#
Generate Python
Parametervalues suitable for functions that are derived from the glyph.- Returns:
list(Parameter)
- classmethod properties(*, _with_props: bool = False) set[str] | dict[str, Property[Any]]#
Collect the names of properties on this class.
Warning
In a future version of Bokeh, this method will return a dictionary mapping property names to property objects. To future-proof this current usage of this method, wrap the return value in
list.- Returns:
property names
- classmethod properties_with_refs() dict[str, Property[Any]]#
Collect the names of all properties on this class that also have references.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
- properties_with_values(*, include_defaults: bool = True, include_undefined: bool = False) dict[str, Any]#
Collect a dict mapping property names to their values.
This method always traverses the class hierarchy and includes properties defined on any parent classes.
Non-serializable properties are skipped and property values are in “serialized” format which may be slightly different from the values you would normally read from the properties; the intent of this method is to return the information needed to losslessly reconstitute the object instance.
- query_properties_with_values(query: Callable[[PropertyDescriptor[Any]], bool], *, include_defaults: bool = True, include_undefined: bool = False) dict[str, Any]#
Query the properties values of
HasPropsinstances with a predicate.- Parameters:
query (callable) – A callable that accepts property descriptors and returns True or False
include_defaults (bool, optional) – Whether to include properties that have not been explicitly set by a user (default: True)
- Returns:
mapping of property names and values for matching properties
- Return type:
- select(selector: SelectorType) Iterable[Model]#
Query this object and all of its references for objects that match the given selector.
- Parameters:
selector (JSON-like)
- Returns:
seq[Model]
- select_one(selector: SelectorType) Model | None#
Query this object and all of its references for objects that match the given selector. Raises an error if more than one object is found. Returns single matching object, or None if nothing is found.
- Parameters:
selector (JSON-like)
- Returns:
Model
- set_from_json(name: str, value: Any, *, setter: Setter | None = None) None#
Set a property value on this object from JSON.
- Parameters:
name (str) – name of the attribute to set
value (JSON-value) – value to set to the attribute to
setter (ClientSession or ServerSession or None, optional) –
This is used to prevent “boomerang” updates to Bokeh apps.
In the context of a Bokeh server application, incoming updates to properties will be annotated with the session that is doing the updating. This value is propagated through any subsequent change notifications that the update triggers. The session can compare the event setter to itself, and suppress any updates that originate from itself.
- Returns:
None
- set_select(selector: type[Model] | SelectorType, updates: dict[str, Any]) None#
Update objects that match a given selector with the specified attribute/value updates.
- Parameters:
selector (JSON-like)
updates (dict)
- Returns:
None
- themed_values() dict[str, Any] | None#
Get any theme-provided overrides.
Results are returned as a dict from property name to value, or
Noneif no theme overrides any values for this instance.- Returns:
dict or None
- to_serializable(serializer: Serializer) ObjectRefRep#
Converts this object to a serializable representation.
- trigger(attr: str, old: Any, new: Any, hint: DocumentPatchedEvent | None = None, setter: Setter | None = None) None#
- update(**kwargs: Any) None#
Updates the object’s properties from the given keyword arguments.
- Returns:
None
Examples
The following are equivalent:
from bokeh.models import Range1d r = Range1d # set properties individually: r.start = 10 r.end = 20 # update properties together: r.update(start=10, end=20)
JSON Prototype
{
"align": "auto",
"aspect_ratio": null,
"auto_edit": false,
"autosize_mode": "force_fit",
"columns": [],
"context_menu": null,
"css_classes": [],
"css_variables": {
"type": "map"
},
"disabled": false,
"editable": false,
"elements": [],
"fit_columns": null,
"flow_mode": "block",
"frozen_columns": null,
"frozen_rows": null,
"header_row": true,
"height": 400,
"height_policy": "auto",
"html_attributes": {
"type": "map"
},
"html_id": null,
"id": "p58730",
"index_header": "#",
"index_position": 0,
"index_width": 40,
"js_event_callbacks": {
"type": "map"
},
"js_property_callbacks": {
"type": "map"
},
"margin": 5,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"multi_selectable": true,
"name": null,
"reorderable": true,
"resizable": false,
"row_height": 25,
"scroll_to_selection": true,
"selectable": true,
"sizing_mode": null,
"sortable": true,
"source": {
"attributes": {
"data": {
"type": "map"
},
"selected": {
"attributes": {
"indices": [],
"line_indices": []
},
"id": "p58732",
"name": "Selection",
"type": "object"
},
"selection_policy": {
"id": "p58733",
"name": "UnionRenderers",
"type": "object"
}
},
"id": "p58731",
"name": "ColumnDataSource",
"type": "object"
},
"styles": {
"type": "map"
},
"stylesheets": [],
"subscribed_events": {
"type": "set"
},
"syncable": true,
"tags": [],
"view": {
"attributes": {
"filter": {
"id": "p58735",
"name": "AllIndices",
"type": "object"
}
},
"id": "p58734",
"name": "CDSView",
"type": "object"
},
"visible": true,
"width": 600,
"width_policy": "auto"
}