Skip to content

Commit 7fa2581

Browse files
author
Ryan Patrick Kyle
committed
🐛 fix issue with initial NULL value handling in _dash-update-component
1 parent 8362cb5 commit 7fa2581

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

Diff for: R/dash.R

+30-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@ Dash <- R6::R6Class(
212212

213213
dash_update <- paste0(self$config$routes_pathname_prefix, "_dash-update-component")
214214
route$add_handler("post", dash_update, function(request, response, keys, ...) {
215-
216215
request <- request_parse_json(request)
217216

218217
if (!"output" %in% names(request$body)) {
@@ -230,7 +229,36 @@ Dash <- R6::R6Class(
230229
stop(sprintf("Couldn't find a callback function associated with '%s'", thisOutput))
231230
}
232231

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+
234262
output_value <- do.call(callback, callback_args)
235263

236264
# have to format the response body like this

0 commit comments

Comments
 (0)