☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

DataCube 'selectable' and 'editable'

Community Support
WWatson
WWatson

What I’m trying to do
Select members of a DataCube and get the selected items. Less importantly, edit the members of a DataCube.

It looks as though the DataCube widget takes both selectable and editable keywords upon creation, but these do not appear to do anything.

Minimum reproducible example
from bokeh.document import Document
from bokeh.embed import file_html
from bokeh.models import (ColumnDataSource, DataCube, GroupingInfo, CustomJS, TableColumn, DataTable, Button)
from bokeh.resources import INLINE
from bokeh.util.browser import view
from bokeh.layouts import row, column
import io

source_cube = ColumnDataSource(data=dict(
    d0=['A', 'E', 'E', 'E', 'J', 'L', 'M'],
    d1=['B', 'D', 'D', 'H', 'K', 'L', 'N'],
    d2=['C', 'F', 'G', 'H', 'K', 'L', 'O'],
))
source_table = ColumnDataSource(data=dict(
    d0=['A', 'E', 'E', 'E', 'J', 'L', 'M'],
    d1=['B', 'D', 'D', 'H', 'K', 'L', 'N'],
    d2=['C', 'F', 'G', 'H', 'K', 'L', 'O'],
))

columns_cube = [
    TableColumn(field='d2', title='Name', width=80, sortable=True),
]
columns_table = [
    TableColumn(field='d2', title='Name', width=80, sortable=True),
]

target = ColumnDataSource(data=dict(row_indices=[], labels=[]))
grouping = [
    GroupingInfo(getter='d0'),
    GroupingInfo(getter='d1')
]

table = DataTable(source=source_table, columns=columns_table, selectable=True, editable=True)
cube = DataCube(source=source_cube, columns=columns_cube, grouping=grouping, target=target, selectable=True, editable=True)

popup_table = CustomJS(args=dict(s=source_table), code='''
                      var to_alert = 'indices: ' + s.selected.indices + '\\n';
                      for (var i = 0; i < s.selected.indices.length; i++){
                          to_alert += s.data.d2[s.selected.indices[i]];
                      }
                      alert(to_alert)''')
popup_cube = CustomJS(args=dict(s=source_cube), code='''
                      var to_alert = 'indices: ' + s.selected.indices + '\\n';
                      for (var i = 0; i < s.selected.indices.length; i++){
                          to_alert += s.data.d2[s.selected.indices[i]];
                      }
                      alert(to_alert)''')

button_table = Button(label='Check table')
button_table.js_on_click(popup_table)
button_cube = Button(label='Check cube')
button_cube.js_on_click(popup_cube)

doc = Document()
doc.add_root(row(cube, table, column(button_table, button_cube)))

if __name__ == '__main__':
    doc.validate()
    filename = "data_cube.html"
    with io.open(filename, "w", encoding="utf-8") as f:
        f.write(file_html(doc, INLINE, "Demonstration of Data Cube with Aggregations"))
    print("Wrote", filename)
    view(filename)

(unlike this example my actual code is running as a server)

I’m aware DataCube is somewhat experimental and the documentation on it is spare, but ideally I’d like to be able to get the selected index of any element in it (i.e. the columns and indices of any selected child or parent items). Although less important, it would also be nice to be able to be able to edit the items in the DataCube.

Hopefully I’m just missing something simple!

⌁   Link to post

End of archived discussion · Replies are disabled