@@ -212,7 +212,6 @@ Dash <- R6::R6Class(
212
212
213
213
dash_update <- paste0(self $ config $ routes_pathname_prefix , " _dash-update-component" )
214
214
route $ add_handler(" post" , dash_update , function (request , response , keys , ... ) {
215
-
216
215
request <- request_parse_json(request )
217
216
218
217
if (! " output" %in% names(request $ body )) {
@@ -230,7 +229,36 @@ Dash <- R6::R6Class(
230
229
stop(sprintf(" Couldn't find a callback function associated with '%s'" , thisOutput ))
231
230
}
232
231
233
- callback_args <- lapply(c(request $ body $ inputs , request $ body $ state ), `[[` , 3 )
232
+ # the following callback_args code handles inputs which may contain
233
+ # NULL values; we wish to retain the NULL elements, since these can
234
+ # be passed into the callback handler, rather than dropping the list
235
+ # elements when they are encountered (which also compromises the
236
+ # sequencing of passed arguments). the R FAQ notes that list(NULL)
237
+ # can be used to append NULL elements into a constructed list, but
238
+ # that assigning NULL into list elements omits them from the object.
239
+ #
240
+ # we want the NULL elements to be wrapped in a list when they're
241
+ # passed, so they're nested in the code below.
242
+ #
243
+ # https://cran.r-project.org/doc/FAQ/R-FAQ.html#Others:
244
+ callback_args <- list ()
245
+
246
+ for (input_element in request $ body $ inputs ) {
247
+ if (is.null(input_element $ value ))
248
+ callback_args <- c(callback_args , list (list (NULL )))
249
+ else
250
+ callback_args <- c(callback_args , input_element $ value )
251
+ }
252
+
253
+ if (length(request $ body $ state )) {
254
+ for (state_element in request $ body $ state ) {
255
+ if (is.null(state_element $ value ))
256
+ callback_args <- c(callback_args , list (list (NULL )))
257
+ else
258
+ callback_args <- c(callback_args , state_element $ value )
259
+ }
260
+ }
261
+
234
262
output_value <- do.call(callback , callback_args )
235
263
236
264
# have to format the response body like this
0 commit comments