Open anders-kiaer opened 3 years ago
There are other input on this issue in #1784, specically:
https://github.com/plotly/dash/pull/1784#issuecomment-931620245 https://github.com/plotly/dash/pull/1784#issuecomment-932584610 https://github.com/plotly/dash/pull/1784#issuecomment-937927584
As a side note, this is already supported by the serverside outputs in dash-extensions.
Especially for advanced Dash components, it would be useful if the Dash component author could do serialization/deserialization for the Dash app developer, in order to make an easy component API. Today the component authors are limited to accepting directly JSON-serializable Python objects, and can't e.g. accept instances of custom Python data objects / classes.
One way of achieving this feature could perhaps be roughly along these lines:
1) In
dash.development.base_component.Component
add@classmethods
serialize
anddeserialize
:2) ```python from dash.development.base_component import Component
3) In Dash core, call
SomeDashComponent.(de)serialize
when input/output data for a prop is to be serialized/deserialized.Features possible with this:
pd.DataFrame
) could be serialized in different ways, depending on component. E.g. theDataTable
component, showing data row by row, would in general serialize thepd.DataFrame
in a different way than e.g. a graph component wanting the data serialized in another format (examples could be e.g. performance reasons frontend wanting the data serialized in some specific way, or maybe there for a given component are restrictions/assumptions on thepd.DataFrame
input that can be used to e.g. remove redundant data before sent to the client).typing
(see below)*.*The
typing
module in Python 3+ opens up possibilities for libraries to accomplish all these at the same time:mypy
to check their code for type consistency.mypy
can help detect inconsistencies).Taken down to the context in this issue, type hint annotations could be introduced without breaking change at a later point following something along these lines:
The last point here on type hinting is related to https://github.com/plotly/dash/issues/719#issuecomment-844406378 and #1748.