diff --git a/NEWS.md b/NEWS.md index 34a5d24..8c477af 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # teal.picks 0.1.0.9002 +### Bug fixes + +* Fixed a bug that crashes the `picks_srv` when datasets with labels that contain lists. Defaults to the choice name (#96). + ### Miscellaneous * `variables()` allows for custom `allow-clear` options to be set by user without being overwritten. diff --git a/R/resolver.R b/R/resolver.R index 048d5e4..0ee8608 100644 --- a/R/resolver.R +++ b/R/resolver.R @@ -190,7 +190,14 @@ determine.values <- function(x, data) { # don't rename if names provided by app dev labels <- vapply( out, - FUN = function(choice) c(attr(data[[choice]], "label"), choice)[1], + FUN = function(choice) { + label <- attr(data[[choice]], "labels") + if (checkmate::test_string(label)) { + label + } else { + choice + } + }, FUN.VALUE = character(1) ) stats::setNames(out, labels) diff --git a/tests/testthat/test-module_picks.R b/tests/testthat/test-module_picks.R index 5fb7d3b..89e0393 100644 --- a/tests/testthat/test-module_picks.R +++ b/tests/testthat/test-module_picks.R @@ -200,6 +200,17 @@ testthat::describe("picks_srv return a named list of reactive picks", { }) testthat::describe("picks_srv resolves datasets", { + it("that has a named list label", { + test_data <- list(CO2 = CO2) + test_picks <- picks(datasets(choices = c("CO2"), selected = "CO2")) + shiny::withReactiveDomain( + domain = shiny::MockShinySession$new(), + expr = testthat::expect_no_error( + picks_srv(id = "test", picks = test_picks, data = shiny::reactive(test_data)) + ) + ) + }) + it("provided non-delayed datasets are adjusted to possible datanames", { test_picks <- picks( datasets(choices = c(mtcars = "mtcars", notexisting = "notexisting"), selected = "mtcars")