Dash DataTable - Using Callbacks

How do you use dash-table-experiments together with callback functions?

The code below works for the table without callback, but when I included the call back functionality it does not work, (I get a “Error loading dependencies error”).

import dash
from dash.dependencies import Input, Output
import dash_html_components as html
import dash_table_experiments as dt
import pandas

app = dash.Dash()

DF_SIMPLE = pandas.DataFrame({
‘x’: [‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’],
‘y’: [4, 3, 1, 2, 3, 6],
‘z’: [‘a’, ‘b’, ‘c’, ‘a’, ‘b’, ‘c’]
}).to_dict(‘records’)

app.layout = html.Div(
[
dt.DataTable(
rows=DF_SIMPLE,
id=‘datatable-working’
),
dt.DataTable(id=‘datatable-not-working’)
]
)

@app.callback(Output(‘datatable-not-working’, ‘rows’))
def update_info_table():
return DF_SIMPLE

if name == ‘main’:
app.run_server()

1 Like

I think DataTable is unhappy with rows not having an initial value. dt.DataTable(id=‘datatable-not-working’, rows=[{}]) makes it happy.

4 Likes

That totally worked. Thanks! :smiley:

1 Like