plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.
https://plotly.com/dash
MIT License
21.16k stars 2.04k forks source link

add hooks for component classes #464

Open T4rk1n opened 5 years ago

T4rk1n commented 5 years ago

The generated components gets overwritten every time we run the generation. We can't add python code to them because of that. It would be useful if we could add code that could modify the props before sending it to the front-end.

Solution proposal:

bpostlethwaite commented 5 years ago

Great yes this could be a way to add direct Dataframe parsing support to plotly/dash-table

T4rk1n commented 5 years ago

I refactored the component generation, now every prop will have a descriptor that fires a prop change event (for the backend code only). The returned value from the handler will be the actual value used by the component.

Example dataframe serialization:

def on_prop_change(component, prop_name, old_value, new_value, prop_type):
    if isinstance(new_value, pd.DataFrame):
        return new_value.to_dict('records')
    return new_value

Two options for the prop changes events:

Generate the _component_class._ComponentClass and component_class.Component so the user can override methods & attributes

PROS:

CONS:

Add handlers to global object (ComponentRegistry)

PROS:

CONS:

I favor the second option.