How to get the new dataframe after use datatable edit

I am using Bokeh 2.0.1, I want to edit the data table and use the new data from edited datatable. Is anyone can suggest how to get the new data after edit datatable ( I am pretty new to Bokeh)? Thanks!

from bokeh.models import ColumnDataSource
from bokeh.models.widgets import DataTable, TableColumn, StringEditor, IntEditor
import pandas as pd
from bokeh.io import output_notebook, show
output_notebook()

df = pd.DataFrame([[0, 1,2],[1,4,5], [0,5,6]])
df.columns = [‘x’, ‘one’, ‘two’]
cds = ColumnDataSource(df)

columns = [
TableColumn(field=“one”, title=“ONE”, editor=IntEditor()),
TableColumn(field=“two”, title=“TWO”)
]

dt = DataTable(source=cds, columns=columns,
sortable=True, editable=True, fit_columns=True, selectable=True)

show(dt)
df=dt.source.data

Hi @danwang123 first please edit your post to use code formatting so that the code is intelligible (either with the </> icon on the editing toolbar, or triple backtick ``` fences around the code blocks)

Second, does “get the new data value” mean:

  • get the value in JavaScript? or
  • get the value in Python?

If the latter, then that requires creating and running a Bokeh Server Application which is structured differently from what you have above

Hi , Thanks a lot! I Will pay attention to post code.
I mean get the value from the changed datatable source after editing the datatable in Jupyter notebook. A function which is very similar to qgrid.get_changed_df(). Thanks!

@danwang123 For that you will still need a Bokeh server application, but it is possible to embed Bokeh server applications in a Jupyter notebooks. See this example notebook for the general structure things must be arranged:

https://github.com/bokeh/bokeh/blob/master/examples/howto/server_embed/notebook_embed.ipynb

In your case specifically you will want an on_change callback on the data source that drives the table.