Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setCallbackContext error occurs in pattern-matching callbacks with one or more input IDs as strings #236

Closed
rpkyle opened this issue Oct 29, 2020 · 1 comment
Assignees
Milestone

Comments

@rpkyle
Copy link
Contributor

rpkyle commented Oct 29, 2020

In translating a Python demo app for pattern-matching callbacks with the following signature

app$callback(
  output(id = list("index" = MATCH, "type" = "dynamic-output"), property = "figure"),
  params = list(
      input(id = list("index" = MATCH, "type" = "dynamic-dropdown-x"), property = "value"),
      input(id = list("index" = MATCH, "type" = "dynamic-dropdown-y"), property = "value"),
      input(id = "country", property = "value")

I encountered the error:

values must be length 1,
 but FUN(X[[1]]) result is length 2

I was able to trace this error to setCallbackContext, and the following statement:

dashR/R/utils.R

Line 1065 in add8dd3

id_match <- vapply(callback_elements$inputs, function(x) x$id %in% input_id, logical(1))

I suspect that the issue is that we convert the IDs to JSON-like syntax later in the function, and so the length of the IDs is not uniformly 1:

> input_id                                                                                                                                          
[1] "country"

> callback_elements$inputs                                                                                                                          
[[1]]
[[1]]$id
[[1]]$id$index
[1] 0

[[1]]$id$type
[1] "dynamic-dropdown-x"


[[1]]$property
[1] "value"

[[1]]$value
[1] "year"


[[2]]
[[2]]$id
[[2]]$id$index
[1] 0

[[2]]$id$type
[1] "dynamic-dropdown-y"


[[2]]$property
[1] "value"

[[2]]$value
[1] "gdpPercap"


[[3]]
[[3]]$id
[1] "country"

[[3]]$property
[1] "value"

[[3]]$value
[1] "Bulgaria"

One option is to unlist the IDs when matching on their value. Alternatively, we could consider whether the ordering of the if/else logic within setCallbackContext is ultimately what we want.

Whatever solution we identify, we should ensure that a heterogeneous mix of IDs that are lists and vectors (i.e. using selectors or not) is allowed when describing callbacks so that this error does not occur.

@rpkyle
Copy link
Contributor Author

rpkyle commented Oct 30, 2020

Resolved via #237, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants