diff --git a/NEWS.md b/NEWS.md index 985458d..f5114c1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,7 +4,7 @@ ## New features * `mwModule()` now return `controller` value, with possibility to use new `clear()` method -* add `header` and `footer` arguments to `mwModuleUI()` +* add `header`, `footer` and `fluidRow` arguments to `mwModuleUI()` # manipulateWidget 0.8.0 (2017-10-25) diff --git a/R/module_ui.R b/R/module_ui.R index 1e3b003..4def30e 100644 --- a/R/module_ui.R +++ b/R/module_ui.R @@ -69,10 +69,14 @@ mwModule <- function(id, controller, ...) { #' @param height Height of the module UI. #' @param header Tag or list of tags to display as a common header above all tabPanels. #' @param footer Tag or list of tags to display as a common footer below all tabPanels +#' @param fluidRow Include module in a fluidRow ? Can be usefull in a shiny app. Defaut to FALSE +#' #' @rdname mwModule #' @export -mwModuleUI <- function(id, border = TRUE, okBtn = FALSE, saveBtn = TRUE, margin = 0, width = "100%", height = 400, - header = NULL, footer = NULL) { +mwModuleUI <- function(id, border = TRUE, okBtn = FALSE, saveBtn = TRUE, margin = 0, + width = "100%", height = 400, header = NULL, footer = NULL, + fluidRow = FALSE) { + ns <- shiny::NS(id) for (i in seq_along(margin)) { margin[i] <- shiny::validateCssUnit(margin[i]) @@ -86,20 +90,36 @@ mwModuleUI <- function(id, border = TRUE, okBtn = FALSE, saveBtn = TRUE, margin if(!saveBtn) class <- c(class, "without-save") class <- paste(class, collapse = " ") - res <- shiny::fluidRow( - shiny::column(12, - header, - shiny::uiOutput(ns("ui"), container = function(...) { - tags$div(style=sprintf("width:%s;height:%s;padding:%s", - shiny::validateCssUnit(width), - shiny::validateCssUnit(height), - margin), - class = class, - ...) - }), - footer - ) - ) + if(fluidRow){ + res <- shiny::fluidRow( + shiny::column(12, + header, + shiny::uiOutput(ns("ui"), container = function(...) { + tags$div(style=sprintf("width:%s;height:%s;padding:%s", + shiny::validateCssUnit(width), + shiny::validateCssUnit(height), + margin), + class = class, + ...) + }), + footer + ) + ) + } else { + res <- shiny::tagList( + header, + shiny::uiOutput(ns("ui"), container = function(...) { + tags$div(style=sprintf("width:%s;height:%s;padding:%s", + shiny::validateCssUnit(width), + shiny::validateCssUnit(height), + margin), + class = class, + ...) + }), + footer + ) + } + htmldep <- htmltools::htmlDependency( "manipulateWidget", diff --git a/inst/examples/example-reactive_values.R b/inst/examples/example-reactive_values.R index 787f80b..80bf304 100644 --- a/inst/examples/example-reactive_values.R +++ b/inst/examples/example-reactive_values.R @@ -8,7 +8,7 @@ ui <- fillPage( textInput("title", label = "Title", value = "glop"), selectInput("series", "series", choices = c("series1", "series2", "series3")) ), - mwModuleUI("ui", height = "100%") + mwModuleUI("ui", height = "400px") ) ) diff --git a/man/mwModule.Rd b/man/mwModule.Rd index 0b2206e..4bf7a96 100644 --- a/man/mwModule.Rd +++ b/man/mwModule.Rd @@ -8,7 +8,8 @@ mwModule(id, controller, ...) mwModuleUI(id, border = TRUE, okBtn = FALSE, saveBtn = TRUE, margin = 0, - width = "100\%", height = 400) + width = "100\%", height = 400, header = NULL, footer = NULL, + fluidRow = FALSE) } \arguments{ \item{id}{A unique string that identifies the module} @@ -32,6 +33,12 @@ units.} \item{width}{Width of the module UI.} \item{height}{Height of the module UI.} + +\item{header}{Tag or list of tags to display as a common header above all tabPanels.} + +\item{footer}{Tag or list of tags to display as a common footer below all tabPanels} + +\item{fluidRow}{Include module in a fluidRow ? Can be usefull in a shiny app. Defaut to FALSE} } \value{ \code{mwModuleUI} returns the required HTML elements for the module. mwModule is only diff --git a/tests/testthat/test-mwModuleUI.R b/tests/testthat/test-mwModuleUI.R index 8f315b1..9357f53 100644 --- a/tests/testthat/test-mwModuleUI.R +++ b/tests/testthat/test-mwModuleUI.R @@ -9,15 +9,15 @@ describe("mwModuleUI function", { # default def_mw_ui <- mwModuleUI(id = "def") expect_is(def_mw_ui, "shiny.tag.list") - expect_equal(def_mw_ui[[1]]$name, "div") - expect_equal(def_mw_ui[[1]]$attribs$id, "def-ui") - expect_true(grepl("border", def_mw_ui[[1]]$attribs$class)) + expect_equal(def_mw_ui[[2]]$name, "div") + expect_equal(def_mw_ui[[2]]$attribs$id, "def-ui") + expect_true(grepl("border", def_mw_ui[[2]]$attribs$class)) # parameters def_mw_ui <- mwModuleUI(id = "def", border = FALSE) - expect_false(grepl("border", def_mw_ui[[1]]$attribs$class)) + expect_false(grepl("border", def_mw_ui[[2]]$attribs$class)) def_mw_ui <- mwModuleUI(id = "def", height = "100%") - expect_true(grepl("height:100%", def_mw_ui[[1]]$attribs$style)) + expect_true(grepl("height:100%", def_mw_ui[[2]]$attribs$style)) }) })