diff --git a/dash_uploader/callbacks.py b/dash_uploader/callbacks.py index 8ada20f..3bf64ae 100644 --- a/dash_uploader/callbacks.py +++ b/dash_uploader/callbacks.py @@ -21,6 +21,7 @@ def wrapper( uploaded_files_size, total_files_size, upload_id, + *args, ): if not callbackbump: raise PreventUpdate() @@ -43,7 +44,7 @@ def wrapper( total_size_mb=total_files_size, upload_id=upload_id, ) - return callback(status) + return callback(status, *args) return wrapper @@ -51,6 +52,7 @@ def wrapper( def callback( output, id="dash-uploader", + state=None, # The state parameter is placed last in order to maintain better parameter order compatibility. ): """ Add a callback to dash application. @@ -117,16 +119,22 @@ def add_callback(function): # State: Pass along extra values without firing the callbacks. # # See also: https://dash.plotly.com/basic-callbacks - dash_callback = settings.app.callback( - output, - [Input(id, "dashAppCallbackBump")], - [ + states = [ State(id, "uploadedFileNames"), State(id, "totalFilesCount"), State(id, "uploadedFilesSize"), State(id, "totalFilesSize"), State(id, "upload_id"), - ], + ] + if state: + if isinstance(state, list): + states.extend(state) + else: + states.append(state) + dash_callback = settings.app.callback( + output, + [Input(id, "dashAppCallbackBump")], + states, **kwargs )(dash_callback) diff --git a/usage.py b/usage.py index 481e2f2..ffb130d 100644 --- a/usage.py +++ b/usage.py @@ -5,11 +5,14 @@ import dash if du.utils.dash_version_is_at_least("2.0.0"): + from dash import dcc from dash import html # if dash <= 2.0.0, use: import dash_html_components as html else: import dash_html_components as html + import dash_core_components as dcc -from dash.dependencies import Output + +from dash.dependencies import Output, State app = dash.Dash(__name__) @@ -49,6 +52,7 @@ def get_app_layout(): "display": "inline-block", }, ), + dcc.Store(id="example-token", storage_type="memory", data="some token") ], style={ "textAlign": "center", @@ -65,8 +69,10 @@ def get_app_layout(): @du.callback( output=Output("callback-output", "children"), id="dash-uploader", + state=State("example-token", "data"), # List of State also acceptable ) -def callback_on_completion(status: du.UploadStatus): +def callback_on_completion(status: du.UploadStatus, token): + print("example-token is ", token) return html.Ul([html.Li(str(x)) for x in status.uploaded_files])