11dependency_id_string (id:: NamedTuple ) = sorted_json (id)
22dependency_id_string (id:: String ) = sorted_json (id)
33
4- function dependency_string (dep:: Dependency{Trait, String} ) where {Trait}
4+ function dependency_string (dep:: Dependency{Trait, String} ) where {Trait}
55 return " $(dep. id) .$(dep. property) "
66end
77
8- function dependency_string (dep:: Dependency{Trait, <:NamedTuple} ) where {Trait}
8+ function dependency_string (dep:: Dependency{Trait, <:NamedTuple} ) where {Trait}
99 id_str = replace (
1010 sorted_json (dep. id),
1111 " ." => " \\ ."
3333 state::Union{Vector{State}, State} = []
3434 )
3535
36- Create a callback that updates the output by calling function `func`.
36+ Create a callback that updates the output by calling function `func`.
3737
3838# Examples
3939
@@ -59,9 +59,10 @@ function callback!(func::Union{Function, ClientsideFunction, String},
5959 app:: DashApp ,
6060 output:: Union{Vector{<:Output}, Output} ,
6161 input:: Union{Vector{<:Input}, Input} ,
62- state:: Union{Vector{<:State}, State} = State[]
62+ state:: Union{Vector{<:State}, State} = State[];
63+ prevent_initial_call = nothing
6364 )
64- return _callback! (func, app, CallbackDeps (output, input, state))
65+ return _callback! (func, app, CallbackDeps (output, input, state), prevent_initial_call = prevent_initial_call )
6566end
6667
6768"""
7071 deps...
7172 )
7273
73- Create a callback that updates the output by calling function `func`.
74+ Create a callback that updates the output by calling function `func`.
7475"Flat" version of `callback!` function, `deps` must be ``Output..., Input...[,State...]``
7576
7677# Examples
@@ -85,7 +86,7 @@ app = dash() do
8586
8687 end
8788end
88- callback!(app,
89+ callback!(app,
8990 Output("outputID2", "children"),
9091 Output("outputID", "children"),
9192 Input("graphTitle", "value"),
9798"""
9899function callback! (func:: Union{Function, ClientsideFunction, String} ,
99100 app:: DashApp ,
100- deps:: Dependency...
101+ deps:: Dependency... ;
102+ prevent_initial_call = nothing
101103 )
102104 output = Output[]
103105 input = Input[]
104106 state = State[]
105107 _process_callback_args (deps, (output, input, state))
106- return _callback! (func, app, CallbackDeps (output, input, state, length (output) > 1 ))
108+ return _callback! (func, app, CallbackDeps (output, input, state, length (output) > 1 ), prevent_initial_call = prevent_initial_call )
107109end
108110
109111function _process_callback_args (args:: Tuple{T, Vararg} , dest:: Tuple{Vector{T}, Vararg} ) where {T}
@@ -115,20 +117,29 @@ end
115117function _process_callback_args (args:: Tuple , dest:: Tuple{Vector{T}, Vararg} ) where {T}
116118 _process_callback_args (args, Base. tail (dest))
117119end
118- function _process_callback_args (args:: Tuple , dest:: Tuple{} )
120+ function _process_callback_args (args:: Tuple , dest:: Tuple{} )
119121 error (" The callback method must received first all Outputs, then all Inputs, then all States" )
120122end
121- function _process_callback_args (args:: Tuple{} , dest:: Tuple{} )
123+ function _process_callback_args (args:: Tuple{} , dest:: Tuple{} )
122124end
123125
124126
125- function _callback! (func:: Union{Function, ClientsideFunction, String} , app:: DashApp , deps:: CallbackDeps )
126-
127+ function _callback! (func:: Union{Function, ClientsideFunction, String} , app:: DashApp , deps:: CallbackDeps ; prevent_initial_call)
128+
127129 check_callback (func, app, deps)
128-
130+
129131 out_symbol = Symbol (output_string (deps))
130- callback_func = make_callback_func! (app, func, deps)
131- push! (app. callbacks, out_symbol => Callback (callback_func, deps))
132+ callback_func = make_callback_func! (app, func, deps)
133+ push! (
134+ app. callbacks,
135+ out_symbol => Callback (
136+ callback_func,
137+ deps,
138+ isnothing (prevent_initial_call) ?
139+ get_setting (app, :prevent_initial_callbacks ) :
140+ prevent_initial_call
141+ )
142+ )
132143end
133144
134145
0 commit comments