From f3f90279f2c0a715ba3366b7fc1aedc9df6f0522 Mon Sep 17 00:00:00 2001 From: Esra Ay Date: Wed, 11 May 2022 10:58:59 +0300 Subject: [PATCH 1/6] Fix json conversation of strings with single quote --- R/checkbox.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/checkbox.R b/R/checkbox.R index fce96aaf..0c0108e5 100644 --- a/R/checkbox.R +++ b/R/checkbox.R @@ -197,9 +197,9 @@ multiple_checkbox <- function(input_id, label, choices, choices_value = choices, update_multiple_checkbox <- function(session = getDefaultReactiveDomain(), input_id, choices = NULL, choices_value = choices, selected = NULL, label = NULL) { - if (!is.null(selected)) value <- jsonlite::toJSON(selected) else value <- NULL + if (!is.null(selected)) value <- jsonlite::toJSON(gsub( "'", '"', selected)) else value <- NULL if (!is.null(choices)) { - options <- jsonlite::toJSON(data.frame(name = choices, value = choices_value)) + options <- jsonlite::toJSON(data.frame(name = choices, value = gsub( "'", '"', choices_value))) } else { options <- NULL } From 15304c92769d6315d355382c2da55c1e2dc5e61a Mon Sep 17 00:00:00 2001 From: esraay <36202874+esraay@users.noreply.github.com> Date: Sun, 23 Oct 2022 10:28:53 +0300 Subject: [PATCH 2/6] Update R/checkbox.R Remove whitespace Co-authored-by: Jakub Sobolewski <37193264+jakubsob@users.noreply.github.com> --- R/checkbox.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/checkbox.R b/R/checkbox.R index 0c0108e5..0bbf4263 100644 --- a/R/checkbox.R +++ b/R/checkbox.R @@ -197,7 +197,7 @@ multiple_checkbox <- function(input_id, label, choices, choices_value = choices, update_multiple_checkbox <- function(session = getDefaultReactiveDomain(), input_id, choices = NULL, choices_value = choices, selected = NULL, label = NULL) { - if (!is.null(selected)) value <- jsonlite::toJSON(gsub( "'", '"', selected)) else value <- NULL + if (!is.null(selected)) value <- jsonlite::toJSON(gsub("'", '"', selected)) else value <- NULL if (!is.null(choices)) { options <- jsonlite::toJSON(data.frame(name = choices, value = gsub( "'", '"', choices_value))) } else { From b29b41d93a9856c1852030c441cd2e8cc8dc8494 Mon Sep 17 00:00:00 2001 From: esraay <36202874+esraay@users.noreply.github.com> Date: Sun, 23 Oct 2022 10:29:14 +0300 Subject: [PATCH 3/6] Update R/checkbox.R Co-authored-by: Jakub Sobolewski <37193264+jakubsob@users.noreply.github.com> --- R/checkbox.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/checkbox.R b/R/checkbox.R index 0bbf4263..b8990ea0 100644 --- a/R/checkbox.R +++ b/R/checkbox.R @@ -199,7 +199,7 @@ update_multiple_checkbox <- function(session = getDefaultReactiveDomain(), selected = NULL, label = NULL) { if (!is.null(selected)) value <- jsonlite::toJSON(gsub("'", '"', selected)) else value <- NULL if (!is.null(choices)) { - options <- jsonlite::toJSON(data.frame(name = choices, value = gsub( "'", '"', choices_value))) + options <- jsonlite::toJSON(data.frame(name = choices, value = gsub("'", '"', choices_value))) } else { options <- NULL } From 578408e55b704380e95a3841e920af8a995873c2 Mon Sep 17 00:00:00 2001 From: esraay <36202874+esraay@users.noreply.github.com> Date: Sun, 23 Oct 2022 11:27:37 +0300 Subject: [PATCH 4/6] Add test for multiple checkbox and selected values --- tests/testthat/test_multiple_checkbox.R | 60 +++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/testthat/test_multiple_checkbox.R diff --git a/tests/testthat/test_multiple_checkbox.R b/tests/testthat/test_multiple_checkbox.R new file mode 100644 index 00000000..52de1c6a --- /dev/null +++ b/tests/testthat/test_multiple_checkbox.R @@ -0,0 +1,60 @@ +context("multiple checkbox") + +test_that("test multiple_checkbox input values", { + # type + expect_is(multiple_checkbox( + input_id = "checkboxes", + label = NULL, + choices = "" + ), + "shiny.tag") + # empty input + si_str <- + as.character(multiple_checkbox( + input_id = "checkboxes", + label = NULL, + choices = "" + )) + expect_true(any( + grepl( + "
", + si_str, + fixed = TRUE + ) + )) + # label + si_str <- + as.character(multiple_checkbox( + input_id = "checkboxes", + label = "My Label", + choices = "" + )) + expect_true(any( + grepl("", + si_str, fixed = TRUE) + )) + # selected choices + si_str <- + as.character( + multiple_checkbox( + input_id = "checkboxes", + label = "My Label", + choices = c("A's", "B"), + selected = c("A's", "B") + ) + ) + expect_true(any( + grepl( + "", + si_str, + fixed = TRUE + ) + )) + expect_true(any( + grepl( + "", + si_str, + fixed = TRUE + ) + )) +}) From 9055a9660f02be2c390c718e75fe82e16eb621a8 Mon Sep 17 00:00:00 2001 From: Jakub Nowicki Date: Wed, 31 Jan 2024 16:33:42 +0100 Subject: [PATCH 5/6] chore: Update DESCRIPTION and NEWS. --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 55680c89..2bcf58b5 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: shiny.semantic Title: Semantic UI Support for Shiny -Version: 0.5.0.9000 +Version: 0.5.0.9001 Authors@R: c(person("Filip", "Stachura", email = "filip@appsilon.com", role = "aut"), person("Dominik", "Krzeminski", role = "aut"), person("Krystian", "Igras", role = "aut"), diff --git a/NEWS.md b/NEWS.md index ea82d199..8594eb80 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,8 @@ - Fixed `range_input` now returns both lower and upper bound. +- Fixed `update_multiple_checkbox` not supporting choices with single quote. + # [shiny.semantic 0.5.0](https://github.com/Appsilon/shiny.semantic/releases/tag/0.5.0) - `shiny.semantic` no longer uses CDN as the default source of assets. Instead, `semantic.assets` package was introduced. From a2d65e2f2816220d13dd5945313a4068fd13fc5b Mon Sep 17 00:00:00 2001 From: Jakub Nowicki Date: Wed, 31 Jan 2024 16:44:21 +0100 Subject: [PATCH 6/6] test: Fix test for empty input. --- tests/testthat/test_multiple_checkbox.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test_multiple_checkbox.R b/tests/testthat/test_multiple_checkbox.R index 52de1c6a..7b42d7e6 100644 --- a/tests/testthat/test_multiple_checkbox.R +++ b/tests/testthat/test_multiple_checkbox.R @@ -17,7 +17,7 @@ test_that("test multiple_checkbox input values", { )) expect_true(any( grepl( - "
", + "
", si_str, fixed = TRUE )