Skip to content

Commit

Permalink
add fluidRow argument to mwModuleUI + fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
bthieurmel committed Dec 5, 2017
1 parent 180f621 commit e62cbf0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 24 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
52 changes: 36 additions & 16 deletions R/module_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion inst/examples/example-reactive_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
)

Expand Down
9 changes: 8 additions & 1 deletion man/mwModule.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions tests/testthat/test-mwModuleUI.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
})

0 comments on commit e62cbf0

Please sign in to comment.