Alex F
Alex F

Reputation: 955

Bokeh DataTable with one editable column

I have code that makes all columns in a Bokeh DataTable editable, but I'd like to only allow users to edit a single column.

Here is a DataTable example that runs in Jupyter:

import numpy as np
from bokeh.layouts import column, row
from bokeh.models import ColumnDataSource, TableColumn, NumberFormatter
from bokeh.models.widgets import DataTable
from bokeh.plotting import figure, output_file, show, reset_output, output_notebook
from bokeh import events

reset_output()
output_notebook()

data = {'x': [1, 2, 3, 4, 5],
        'y': [6, 7, 2, 3, 6]}

source = ColumnDataSource(data=data)

tbl_columns = [
    TableColumn(field="x", title="Age", width=50),
    TableColumn(field="y", title="Value", width=100, formatter=NumberFormatter(format="$0,0.00"))
]

tbl_selectors = DataTable(source=source, columns=tbl_columns,
                          editable=True,
                          index_position=None)


show(tbl_selectors)

editable=True sets all columns to be editable. Is there a way to make only a single column user-editable, with the rest being only for information? In the example above, I'd like to modify the Value column but leave Age fixed.

Upvotes: 1

Views: 1659

Answers (1)

pborut
pborut

Reputation: 21

I came to same problem. With bokeh 2.2.3, and with some experimenting, I came to solution. One prevents editing in corresponding TableColumn if one sets column editor to abstract editor. editor=CellEditor() Then, no editing in this column takes place.

Upvotes: 2

Related Questions