diff --git a/R/inputs.R b/R/inputs.R index 7a9ae40..8075519 100644 --- a/R/inputs.R +++ b/R/inputs.R @@ -129,7 +129,7 @@ build_dropdown_extra_choices <- function(choices) { if (length(choices) == 0) { choices_js <- "" } else { - choices_js <- paste0(", choices: ", rjson::toJSON(choices)) + choices_js <- paste0(", choices: ", rjson::toJSON(as.list(choices))) } return(choices_js) diff --git a/tests/testthat/test-inputs.R b/tests/testthat/test-inputs.R index 65e5965..d7b2d84 100644 --- a/tests/testthat/test-inputs.R +++ b/tests/testthat/test-inputs.R @@ -34,6 +34,12 @@ test_that("`dropdown_extra` sets choices to blank when length is 0", { expect_equal(choices, "") }) +test_that("`dropdown_extra` serializes a single value as an array", { + choices <- build_dropdown_extra_choices("a") + + expect_equal(choices, ', choices: ["a"]') +}) + test_that("`dropdown_extra` sets choices correctly", { choices <- build_dropdown_extra_choices(letters[1:3])