emilhe / dash-extensions

The dash-extensions package is a collection of utility functions, syntax extensions, and Dash components that aim to improve the Dash development experience
https://www.dash-extensions.com/
MIT License
409 stars 58 forks source link

`memoize=True` has no effect when used with `OperatorOutput` #246

Closed plutonium-94 closed 1 year ago

plutonium-94 commented 1 year ago

Here is a demo application:

# -*- coding: utf-8 -*-
from dash import html, dcc, Output, Input
from dash.exceptions import PreventUpdate
from dash_extensions.enrich import DashProxy, OperatorTransform, OperatorOutput, Operator
import time

app = DashProxy(__name__, transforms=[OperatorTransform()])

app.layout = html.Div([
    dcc.Store(id='store', data=[]),
    html.Div(id='output'),
    dcc.Input(id='input'),
])

@app.callback(OperatorOutput('store', 'data'), Input('input', 'value'), memoize=True)
def update_store(value):
    if value:
        time.sleep(3)
        return Operator().list.append(value)
    raise PreventUpdate

@app.callback(Output('output', 'children'), Input('store', 'data'))
def update_output(data):
    return str(data)

if __name__ == '__main__':
    app.run_server(debug=True)

When some value was inputted, it always required 3 seconds to show the appended value, even if the value has appeared before. Is memoize=True supposed to prevent this?

emilhe commented 1 year ago

No, memoize is only a feature available for serverside outputs. For "normal" callbacks, you can use Flask Caching directly.

plutonium-94 commented 1 year ago

OK. Thanks for reply!