dash icon indicating copy to clipboard operation
dash copied to clipboard

Two way serialization

Open workaholicant opened this issue 3 years ago • 1 comments

Replaces previous PR with squashed commits

Idea

Provide non-lossy data exchange between server & renderer client in initial layout and callbacks, namely two-way serialization that allows either party sends any object then receive it back in its original type.

CHANGELOG

Added a serialization support of pandas.DataFrame as the very first type, which will be followed by a few more types like numpy.array, DateTime, Plotly figures and more.

Quick preview of how serialization work

- Layout

Before :

xValues = numpy.linspace(0, 3, 4)
yValues = numpy.linspace(4, 7, 4)
df = pandas.DataFrame({'x': xValues, 'y': yValues})
table = DataTable(data=df.to_dict('records'), id='data_table_1')

After :

xValues = numpy.linspace(0, 3, 4)
yValues = numpy.linspace(4, 7, 4)
df = pandas.DataFrame({'x': xValues, 'y': yValues})
table = DataTable(data=df, id='data_table_1')

- Callback

Before :

@callback(Output('data_table_2', 'data'), Input('data_table_1', 'data'))
def update(data): # <-- You would receive array object
	return data

After :

@callback(Output('data_table_2', 'data'), Input('data_table_1', 'data'))
def update(data): # <-- You would receive pandas.DataFrame object as it's what you've passed to data_table_1
	return data

workaholicant avatar Nov 17 '21 09:11 workaholicant