Hi all,
I find it very useful to use a dictionary when having a larger callback with multiple inputs.
But when I try the same for callback outputs returning a dictionary I am struggling with the syntax.
I found the callback signature in the manual here:
https://dash.plotly.com/flexible-callback-signatures
Here is a MWE with dict as input and list as output:
from dash import Dash, html, dcc, Output, Input
app = Dash(__name__)
app.layout = html.Div(
[
dcc.Input(id="input"),
dcc.Store(id="storage"),
html.Div([], id="label"),
]
)
@app.callback(
Output("storage", "data"),
Output("label", "children"),
inputs=dict(foo=Input("input", "value")),
)
def getinput(**inputs):
print(inputs["foo"])
return [inputs["foo"], inputs["foo"]]
if __name__ == "__main__":
app.run_server(debug=True, port=8051)
but when trying with dict as output I get an error:
from dash import Dash, html, dcc, Output, Input
app = Dash(__name__)
app.layout = html.Div(
[
dcc.Input(id="input"),
dcc.Store(id="storage"),
html.Div([], id="label"),
]
)
@app.callback(
outputs=dict(store=Output("storage", "data"), label=Output("label", "children")),
inputs=dict(foo=Input("input", "value")),
)
def getinput(**inputs):
print(inputs["foo"])
return dict(store=inputs["foo"], label=inputs["foo"])
if __name__ == "__main__":
app.run_server(debug=True, port=8051)
the error is:
Please provide an output for this callback:
{
"clientside_function": null,
"inputs": [
{
"id": "input",
"property": "value"
}
],
"long": null,
"output": "....",
"prevent_initial_call": false,
"state": [],
"outputs": [
{
"id": "",
"property": "",
"out": true
}
]
}
How can I access the “outputs” dictionary and set values for the keys “store” and “label”?
Thank you for your help!