From 1273034898206873ffca362ddc1407d3504837d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?fran=C3=A7ois=20GUILLEM?= Date: Tue, 21 Feb 2017 14:20:30 +0100 Subject: [PATCH] Conditional group of inputs (#33) --- DESCRIPTION | 4 ++-- R/controlsUtils.R | 17 ++++++++++++++--- R/mwControlsUI.R | 10 +++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 8ebcce5..5edbe1d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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, @@ -31,6 +31,6 @@ Suggests: xts, rmarkdown LazyData: TRUE -RoxygenNote: 5.0.1 +RoxygenNote: 6.0.0 VignetteBuilder: knitr Encoding: UTF-8 diff --git a/R/controlsUtils.R b/R/controlsUtils.R index dd852a3..cad9dd8 100644 --- a/R/controlsUtils.R +++ b/R/controlsUtils.R @@ -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, @@ -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. diff --git a/R/mwControlsUI.R b/R/mwControlsUI.R index dfd056c..1151ee1 100644 --- a/R/mwControlsUI.R +++ b/R/mwControlsUI.R @@ -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