Skip to content

Commit

Permalink
pickerInput: fix choicesOpts with grouped choices
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Dec 28, 2023
1 parent 93c15fd commit 8ad572f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: shinyWidgets
Title: Custom Inputs Widgets for Shiny
Version: 0.8.0.9000
Version: 0.8.0.9100
Authors@R: c(
person("Victor", "Perrier", email = "victor.perrier@dreamrs.fr", role = c("aut", "cre", "cph")),
person("Fanny", "Meyer", role = "aut"),
Expand Down
65 changes: 35 additions & 30 deletions R/input-selectpicker.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ pickerInput <- function(inputId,
class = "selectpicker form-control"
)
selectTag <- tagAppendChildren(
tag = selectTag, pickerSelectOptions(choices, selected, choicesOpt, maxOptGroup)
tag = selectTag,
pickerSelectOptions(choices, selected, choicesOpt, maxOptGroup)
)

if (multiple)
Expand Down Expand Up @@ -274,38 +275,42 @@ pickerSelectOptions <- function(choices, selected = NULL, choicesOpt = NULL, max
if (!is.null(maxOptGroup))
maxOptGroup <- rep_len(x = maxOptGroup, length.out = sum(l))
m <- matrix(data = c(c(1, cumsum(l)[-length(l)] + 1), cumsum(l)), ncol = 2)
html <- lapply(seq_along(choices), FUN = function(i) {
label <- names(choices)[i]
choice <- choices[[i]]
if (is.list(choice)) {
tags$optgroup(
label = htmlEscape(label, TRUE),
`data-max-options` = if (!is.null(maxOptGroup)) maxOptGroup[i],
pickerSelectOptions(
choice, selected,
choicesOpt = lapply(
X = choicesOpt,
FUN = function(j) {
j[m[i, 1]:m[i, 2]]
}
html <- lapply(
X = seq_along(choices),
FUN = function(i) {
label <- names(choices)[i]
choice <- choices[[i]]
if (is.list(choice)) {
tags$optgroup(
label = htmlEscape(label, TRUE),
`data-max-options` = if (!is.null(maxOptGroup)) maxOptGroup[i],
pickerSelectOptions(
choice, selected,
choicesOpt = lapply(
X = choicesOpt,
FUN = function(j) {
j[m[i, 1]:m[i, 2]]
}
)
)
)
)
} else {
tags$option(
value = choice,
HTML(htmlEscape(label)),
style = choicesOpt$style[i],
class = choicesOpt$class[i],
`data-icon` = choicesOpt$icon[i],
`data-subtext` = choicesOpt$subtext[i],
`data-content` = choicesOpt$content[i],
`data-tokens` = choicesOpt$tokens[i],
disabled = if (!is.null(choicesOpt$disabled[i]) && choicesOpt$disabled[i]) "disabled",
selected = if (choice %in% selected) "selected" else NULL
)
} else {
ii <- m[i, 1]
tags$option(
value = choice,
HTML(htmlEscape(label)),
style = choicesOpt$style[ii],
class = choicesOpt$class[ii],
`data-icon` = choicesOpt$icon[ii],
`data-subtext` = choicesOpt$subtext[ii],
`data-content` = choicesOpt$content[ii],
`data-tokens` = choicesOpt$tokens[ii],
disabled = if (!is.null(choicesOpt$disabled[ii]) && choicesOpt$disabled[ii]) "disabled",
selected = if (choice %in% selected) "selected" else NULL
)
}
}
})
)
return(tagList(html))
}

Expand Down
3 changes: 0 additions & 3 deletions tests/testthat/test-checkboxGroupButtons.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@


context("checkboxGroupButtons")

library("shiny")


test_that("Default", {

Expand Down
3 changes: 0 additions & 3 deletions tests/testthat/test-radioGroupButtons.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@


context("radioGroupButtons")

library("shiny")


test_that("Default", {

Expand Down

0 comments on commit 8ad572f

Please sign in to comment.