Skip to content

Commit

Permalink
Fix awesome checkbox & radio with modules
Browse files Browse the repository at this point in the history
  • Loading branch information
pvictor committed Nov 9, 2017
1 parent 9734272 commit 931065a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 12 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.3.7.920
Version: 0.3.7.930
Authors@R: c(
person("Victor", "Perrier", email = "victor.perrier@dreamrs.fr", role = c("aut", "cre")),
person("Fanny", "Meyer", email = "fanny.meyer@dreamrs.fr", role = c("aut")),
Expand Down
9 changes: 3 additions & 6 deletions R/input-awesomecheckbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ awesomeCheckbox <- function (inputId, label, value = FALSE, status = "primary",

# Generate several checkbox

generateAwesomeOptions <- function (inputId, choices, selected, inline, status)
generateAwesomeOptions <- function(inputId, choices, selected, inline, status)
{
options <- mapply(choices, names(choices), FUN = function(value,
name) {
Expand Down Expand Up @@ -239,16 +239,13 @@ awesomeCheckboxGroup <- function (inputId, label, choices, selected = NULL, inli
#'
#' }
updateAwesomeCheckboxGroup <- function (session, inputId, label = NULL, choices = NULL, selected = NULL,
inline = FALSE, status = "primary")
{
if (is.null(selected) && !is.null(choices))
selected <- choices[[1]]
inline = FALSE, status = "primary") {
if (!is.null(choices))
choices <- choicesWithNames(choices)
if (!is.null(selected))
selected <- validateSelected(selected, choices, inputId)
options <- if (!is.null(choices)) {
format(tagList(generateAwesomeOptions(inputId, choices, selected, inline, status)))
format(tagList(generateAwesomeOptions(session$ns(inputId), choices, selected, inline, status)))
}
message <- dropNulls(list(label = label, options = options,
value = selected))
Expand Down
11 changes: 8 additions & 3 deletions R/input-awesomeradio.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,16 @@ generateAwesomeRadio <- function(inputId, choices, selected, inline, status, che
awesomeRadio <- function(inputId, label, choices, selected = NULL, inline = FALSE, status = "primary", checkbox = FALSE) {
choices <- choicesWithNames(choices)
selected <- shiny::restoreInput(id = inputId, default = selected)
selected <- if (is.null(selected)) {
choices[[1]]
} else {
as.character(selected)
}
awesomeRadioTag <- htmltools::tags$div(
id=inputId, class="form-group awesome-radio-class shiny-input-container",
id=inputId, class="form-group shiny-input-radiogroup awesome-radio-class shiny-input-container",
class=if(inline) "shiny-input-container-inline",
if (!is.null(label)) htmltools::tags$label(class="control-label", `for`=inputId, label, style="margin-bottom: 5px; "),
if (!is.null(label)) htmltools::tags$br(),
if (!is.null(label) & !inline) tags$div(style="height: 7px;"),
generateAwesomeRadio(inputId, choices, selected, inline, status, checkbox)
)
# Dep
Expand Down Expand Up @@ -214,7 +219,7 @@ updateAwesomeRadio <- function (session, inputId, label = NULL, choices = NULL,
if (!is.null(selected))
selected <- validateSelected(selected, choices, inputId)
options <- if (!is.null(choices)) {
format(htmltools::tagList(generateAwesomeRadio(inputId, choices, selected, inline, status, checkbox)))
format(htmltools::tagList(generateAwesomeRadio(session$ns(inputId), choices, selected, inline, status, checkbox)))
}
message <- dropNulls(list(label = label, options = options,
value = selected))
Expand Down
2 changes: 1 addition & 1 deletion inst/www/shinyWidgets-bindings.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions inst/www/uglify.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ writeLines(text = js_files, con = "inst/www/shinyWidgets.min.js")
# create one file with all bindings
bindings_files <- list.files(path = "inst/www/", pattern = "bindings", full.names = TRUE, recursive = TRUE)
bindings_files <- bindings_files[bindings_files != "inst/www/shinyWidgets-bindings.min.js"]
bindings_files <- bindings_files[!grepl(pattern = "awesome", bindings_files)]
bindings_files <- lapply(bindings_files, readLines)
bindings_files <- lapply(bindings_files, paste, collapse = "\n")
bindings_files <- paste(unlist(bindings_files), collapse = "\n")
Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-updateAwesomeCheckboxGroup.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ context("updateAwesomeCheckboxGroup")
test_that("Send message", {

session <- as.environment(list(
ns = function(x) {x},
sendInputMessage = function(inputId, message) {
session$lastInputMessage = list(id = inputId, message = message)
}
Expand All @@ -13,7 +14,7 @@ test_that("Send message", {
updateAwesomeCheckboxGroup(session = session, inputId = "idawcbsw", choices = c("A", "B", "C"))
resultACB <- session$lastInputMessage

expect_equal("A", resultACB$message$value)
# expect_equal("A", resultACB$message$value)
expect_true(grepl('"idawcbsw"', resultACB$message$options))

})
1 change: 1 addition & 0 deletions tests/testthat/test-updateAwesomeRadio.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ context("updateAwesomeRadio")
test_that("Send message", {

session <- as.environment(list(
ns = function(x) {x},
sendInputMessage = function(inputId, message) {
session$lastInputMessage = list(id = inputId, message = message)
}
Expand Down

0 comments on commit 931065a

Please sign in to comment.