dash icon indicating copy to clipboard operation
dash copied to clipboard

[Feature Request] Global set_props in backend callbacks.

Open T4rk1n opened this issue 1 year ago • 2 comments
trafficstars

Add a global dash.set_props to be used in callbacks to set arbitrary props not defined in the callbacks outputs, similar to the clientside dash_clientside.set_props.

Example:

app.layout =  html.Div([
    html.Div(id="output"),
    html.Div(id="secondary-output"),
    html.Button("click", id="clicker"),
])

@app.callback(
    Output("output", "children"),
    Input("clicker", "n_clicks"),
    prevent_initial_call=True,
)
def on_click(n_clicks):
    set_props("secondary-output", {"children": "secondary"})
    return f"Clicked {n_clicks} times"

T4rk1n avatar Mar 20 '24 16:03 T4rk1n

Are you thinking this will be implemented and responding back alongside the same callback method? Or will this set_props immediately trigger something on the clientside?

BSd3v avatar Mar 21 '24 14:03 BSd3v

Are you thinking this will be implemented and responding back alongside the same callback method? Or will this set_props immediately trigger something on the clientside?

For regular callback I am planning on adding the new props to the callback response data, on the renderer side this update the layout at the same as the rest of the outputs.

For background callback, adding a cached set_props value to retrieve on requests and apply as side update like the set_progress, independent of the output response.

T4rk1n avatar Mar 21 '24 14:03 T4rk1n