@@ -211,6 +211,15 @@ class Dash(object):
211
211
env: ``DASH_SUPPRESS_CALLBACK_EXCEPTIONS``
212
212
:type suppress_callback_exceptions: boolean
213
213
214
+ :param prevent_initial_callbacks: Default ``False``: Sets the default value
215
+ of ``prevent_initial_call`` for all callbacks added to the app.
216
+ Normally all callbacks are fired when the associated outputs are first
217
+ added to the page. You can disable this for individual callbacks by
218
+ setting ``prevent_initial_call`` in their definitions, or set it
219
+ ``True`` here in which case you must explicitly set it ``False`` for
220
+ those callbacks you wish to have an initial call. This setting has no
221
+ effect on triggering callbacks when their inputs change later on.
222
+
214
223
:param show_undo_redo: Default ``False``, set to ``True`` to enable undo
215
224
and redo buttons for stepping through the history of the app state.
216
225
:type show_undo_redo: boolean
@@ -241,6 +250,7 @@ def __init__(
241
250
external_scripts = None ,
242
251
external_stylesheets = None ,
243
252
suppress_callback_exceptions = None ,
253
+ prevent_initial_callbacks = False ,
244
254
show_undo_redo = False ,
245
255
plugins = None ,
246
256
** obsolete
@@ -288,6 +298,7 @@ def __init__(
288
298
suppress_callback_exceptions = get_combined_config (
289
299
"suppress_callback_exceptions" , suppress_callback_exceptions , False
290
300
),
301
+ prevent_initial_callbacks = prevent_initial_callbacks ,
291
302
show_undo_redo = show_undo_redo ,
292
303
)
293
304
self .config .set_read_only (
@@ -814,6 +825,9 @@ def dependencies(self):
814
825
return flask .jsonify (self ._callback_list )
815
826
816
827
def _insert_callback (self , output , inputs , state , prevent_initial_call ):
828
+ if prevent_initial_call is None :
829
+ prevent_initial_call = self .config .prevent_initial_callbacks
830
+
817
831
_validate .validate_callback (output , inputs , state )
818
832
callback_id = create_callback_id (output )
819
833
callback_spec = {
@@ -832,7 +846,7 @@ def _insert_callback(self, output, inputs, state, prevent_initial_call):
832
846
return callback_id
833
847
834
848
def clientside_callback (
835
- self , clientside_function , output , inputs , state = (), prevent_initial_call = False
849
+ self , clientside_function , output , inputs , state = (), prevent_initial_call = None
836
850
):
837
851
"""Create a callback that updates the output by calling a clientside
838
852
(JavaScript) function instead of a Python function.
@@ -893,6 +907,10 @@ def clientside_callback(
893
907
Input('another-input', 'value')]
894
908
)
895
909
```
910
+
911
+ The last, optional argument `prevent_initial_call` causes the callback
912
+ not to fire when its outputs are first added to the page. Defaults to
913
+ `False` unless `prevent_initial_callbacks=True` at the app level.
896
914
"""
897
915
self ._insert_callback (output , inputs , state , prevent_initial_call )
898
916
@@ -925,7 +943,18 @@ def clientside_callback(
925
943
"function_name" : function_name ,
926
944
}
927
945
928
- def callback (self , output , inputs , state = (), prevent_initial_call = False ):
946
+ def callback (self , output , inputs , state = (), prevent_initial_call = None ):
947
+ """
948
+ Normally used as a decorator, `@app.callback` provides a server-side
949
+ callback relating the values of one or more `output` items to one or
950
+ more `input` items which will trigger the callback when they change,
951
+ and optionally `state` items which provide additional information but
952
+ do not trigger the callback directly.
953
+
954
+ The last, optional argument `prevent_initial_call` causes the callback
955
+ not to fire when its outputs are first added to the page. Defaults to
956
+ `False` unless `prevent_initial_callbacks=True` at the app level.
957
+ """
929
958
callback_id = self ._insert_callback (output , inputs , state , prevent_initial_call )
930
959
multi = isinstance (output , (list , tuple ))
931
960
0 commit comments