Hi,
Thank you in advance for any support.
I am trying to create a callback which updates a single Output when any one of a number of ServersideOutput stores are updated. I have successfully used the ALL pattern matching callback to do this with a regular ‘Store’ component but there’s a problem when I try to use ServersideOutput.
What I see is, instead of returning the data, it returns a hash (like what the resulting filename would be when stored) but the file is never written to the local ‘file_system_store/’ folder.
Is this a bug or is there a way to alter my code to achieve what I want?
Full minimal app code pasted below:
from dash import html, dcc, callback, Input, Output, ctx
from dash_extensions.enrich import (
callback,
Output,
Input,
ServersideOutput,
html,
dcc,
DashProxy,
ServersideOutputTransform,
)
from dash.dependencies import MATCH, ALL
app = DashProxy(__name__, compress=True, transforms=[ServersideOutputTransform()])
app.layout = html.Div(
[
html.Button("A", {"type": "button", "index": "A"}),
html.Button("B", {"type": "button", "index": "B"}),
dcc.Store(id={"type": "store", "index": "A"}, data=[]),
dcc.Store(id={"type": "store", "index": "B"}, data=[]),
dcc.Store(id={"type": "serverside-store", "index": "A"}, data=[]),
dcc.Store(id={"type": "serverside-store", "index": "B"}, data=[]),
html.H1("Serverside storage data using MATCH:"),
html.Div(id={"type": "serverside-store-output", "index": "A"}, children=[]),
html.Div(id={"type": "serverside-store-output", "index": "B"}, children=[]),
html.H1("Regular storage data using ALL:"),
html.Div(id="many-to-one-output", children=[]),
html.H1("Serverside storage data using ALL:"),
html.Div(id="many-to-one-serside-output", children=[]),
]
)
# Regular Store
@callback(
Output({"type": "store", "index": MATCH}, "data"),
Input({"type": "button", "index": MATCH}, "n_clicks"),
prevent_initail_call=True
)
def store(clicks):
button_id = ctx.triggered_id if not None else "No clicks yet"
return f"{button_id} : {clicks}"
# Serverside Store
@callback(
ServersideOutput({"type": "serverside-store", "index": MATCH}, "data"),
Input({"type": "button", "index": MATCH}, "n_clicks"),
prevent_initail_call=True,
)
def serverside_store(clicks):
button_id = ctx.triggered_id if not None else "No clicks yet"
return f"{button_id} : {clicks}"
@callback(
Output({"type": "serverside-store-output", "index": MATCH}, "children"),
Input({"type": "serverside-store", "index": MATCH}, "data"),
prevent_initail_call=True,
)
def serverside_output(data):
return data
# many-to-one
@callback(
Output("many-to-one-output", "children"),
Input({"type": "store", "index": ALL}, "data"),
prevent_initail_call=True,
)
def many_to_one_output(data):
return data
# many-to-one from serverside storage
@callback(
Output("many-to-one-serside-output", "children"),
Input({"type": "serverside-store", "index": ALL}, "data"),
prevent_initail_call=True,
)
def many_to_one_output(data):
return data
if __name__ == "__main__":
app.run_server(debug=True)