Finally, I found a few minutes to further research this issue. It seems that the issue only occurs with Pandas dataframes:
The example from the documentation works.
However, if I modify it slightly to store a dataframe it does not (dash-extensions==1.0.0):
import time
import plotly.express as px
from dash_extensions.enrich import DashProxy, Output, Input, State, Serverside, html, dcc, \
ServersideOutputTransform
app = DashProxy(transforms=[ServersideOutputTransform()])
app.layout = html.Div(
[
html.Button("Query data", id="btn"),
dcc.Dropdown(id="dd"),
dcc.Graph(id="graph"),
dcc.Loading(dcc.Store(id="store"), fullscreen=True, type="dot"),
dcc.Store(id="store-df")
]
)
@app.callback(Output("store", "data"), Input("btn", "n_clicks"), prevent_initial_call=True)
def query_data(n_clicks):
time.sleep(3) # emulate slow database operation
return Serverside(px.data.gapminder()) # no JSON serialization here
@app.callback(Output("dd", "options"), Output("dd", "value"), Input("store", "data"), prevent_initial_call=True)
def update_dd(df):
options = [{"label": column, "value": column} for column in df["year"]] # no JSON de-serialization here
return options, options[0]['value']
@app.callback(Output("store-df", "data"), Output("graph", "figure"), [Input("dd", "value"), State("store", "data")], prevent_initial_call=True)
def update_graph(value, df):
df = df.query("year == {}".format(value)) # no JSON de-serialization here
return Serverside(df), px.sunburst(df, path=["continent", "country"], values="pop", color="lifeExp", hover_data=["iso_alpha"])
if __name__ == "__main__":
app.run_server()
But, if I revert to the previous version of the extensions it does work (dash-extensions==0.1.13):
import time
import plotly.express as px
from dash_extensions.enrich import DashProxy, Output, Input, State, ServersideOutput, html, dcc, \
ServersideOutputTransform
app = DashProxy(transforms=[ServersideOutputTransform()])
app.layout = html.Div(
[
html.Button("Query data", id="btn"),
dcc.Dropdown(id="dd"),
dcc.Graph(id="graph"),
dcc.Loading(dcc.Store(id="store"), fullscreen=True, type="dot"),
dcc.Store(id="store-df")
]
)
@app.callback(ServersideOutput("store", "data"), Input("btn", "n_clicks"), prevent_initial_call=True)
def query_data(n_clicks):
time.sleep(3) # emulate slow database operation
return px.data.gapminder() # no JSON serialization here
@app.callback(Output("dd", "options"), Output("dd", "value"), Input("store", "data"), prevent_initial_call=True)
def update_dd(df):
options = [{"label": column, "value": column} for column in df["year"]] # no JSON de-serialization here
return options, options[0]['value']
@app.callback(ServersideOutput("store-df", "data"), Output("graph", "figure"), [Input("dd", "value"), State("store", "data")], prevent_initial_call=True)
def update_graph(value, df):
df = df.query("year == {}".format(value)) # no JSON de-serialization here
return df, px.sunburst(df, path=["continent", "country"], values="pop", color="lifeExp", hover_data=["iso_alpha"])
if __name__ == "__main__":
app.run_server()
Is this a bug, a feature or a subproduct of my ignorance?