Skip to content

Commit

Permalink
Conditional group of inputs (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoisGuillem committed Feb 21, 2017
1 parent 36c072d commit 1273034
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Description: Like package 'manipulate' does for static graphics, this package
helps to easily add controls like sliders, pickers, checkboxes, etc. that
can be used to modify the input data or the parameters of an interactive
chart created with package 'htmlwidgets'.
BugReports: https://github.com/rte-antares-rpackage/manipulateWidget/issues
URL: https://github.com/rte-antares-rpackage/manipulateWidget
BugReports: https://goo.gl/pV7o5c
License: GPL (>= 2) | file LICENSE
Imports:
shiny,
Expand All @@ -31,6 +31,6 @@ Suggests:
xts,
rmarkdown
LazyData: TRUE
RoxygenNote: 5.0.1
RoxygenNote: 6.0.0
VignetteBuilder: knitr
Encoding: UTF-8
17 changes: 14 additions & 3 deletions R/controlsUtils.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ getControlDesc <- function(controls) {
params <<- append(params, list(attr(x, "params")))
} else if (length(x) == 0) {
return()
} else mapply(getControlDescRecursive, x=x, name = names(x), level = level + 1)
} else {
inputNames <<- append(inputNames, name)
initValues <<- append(initValues, list(NULL))
types <<- append(types, "group")
groupLevel <<- append(groupLevel, level)
multiple <<- append(multiple, NA)
params <<- append(params, list(NULL))
mapply(getControlDescRecursive, x=x, name = names(x), level = level + 1)
}
}
getControlDescRecursive(controls)
getControlDescRecursive(controls, ".root")

data.frame(
res <- data.frame(
name = inputNames,
initValue = I(initValues),
type = types,
Expand All @@ -52,6 +60,9 @@ getControlDesc <- function(controls) {
params = I(params),
stringsAsFactors = FALSE
)

res <- res[res$type != "group",]
res
}

# Internal function that filters a list of controls given a vector of names.
Expand Down
10 changes: 5 additions & 5 deletions R/mwControlsUI.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ mwControlsUI <- function(controlList, .dir = c("v", "h"), .n = 1, .updateBtn = F
params$inputId <- id
params$width <- ifelse(.dir == "v", "100%", "180px")

res <- shiny::conditionalPanel(
condition = sprintf("input.%s_visible", id),
f(params)
)
res <- f(params)
}

res
shiny::conditionalPanel(
condition = sprintf("input.%s_visible", id),
res
)
},
f = controlList, id = ids,
SIMPLIFY = FALSE, USE.NAMES = FALSE
Expand Down

0 comments on commit 1273034

Please sign in to comment.