Skip to content

Commit

Permalink
add .updateInitBtn argument
Browse files Browse the repository at this point in the history
  • Loading branch information
bthieurmel committed Oct 30, 2017
1 parent f1fcaf9 commit 7d55959
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
14 changes: 7 additions & 7 deletions R/controller.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#' @field nrow Number of rows.
#' @field ncol Number of columns.
#' @field autoUpdate Boolean indicating if charts should be automatically
#' updated when a value changes
#' updated when a value changes. list with \code{value} and \code{initBtn} (not autoUpdate, if want first charts on init)
#'
#' @export
MWController <- setRefClass(
Expand All @@ -51,7 +51,7 @@ MWController <- setRefClass(
"returnFunc", "initialized"),
methods = list(

initialize = function(expr, inputs, autoUpdate = TRUE, nrow = NULL,
initialize = function(expr, inputs, autoUpdate = list(value = TRUE, initBtn = FALSE), nrow = NULL,
ncol = NULL, returnFunc = function(widget, envs) {widget}) {
expr <<- expr
inputList <<- inputs$inputList
Expand Down Expand Up @@ -119,7 +119,7 @@ MWController <- setRefClass(
oldValue <- getValue(name, chartId)
newValue <- inputList$setValue(name, value, chartId, reactive = reactive)
if (!initialized) return()
if (autoUpdate && !identical(oldValue, newValue)) {
if (autoUpdate$value && !identical(oldValue, newValue)) {
if (inputList$isShared(name)) updateCharts()
else updateChart(chartId)
}
Expand All @@ -129,7 +129,7 @@ MWController <- setRefClass(
oldValue <- getValueById(id)
newValue <- inputList$setValue(inputId = id, value = value)
if (!initialized) return()
if (autoUpdate && !identical(oldValue, newValue)) {
if (autoUpdate$value && !identical(oldValue, newValue)) {
if (grepl("^shared_", id)) updateCharts()
else {
chartId <- get(".id", envir = inputList$inputs[[id]]$env)
Expand Down Expand Up @@ -220,7 +220,7 @@ MWController <- setRefClass(
function(ns, okBtn = gadget, width = "100%", height = "400px") {
#ns <- shiny::NS(id)
mwUI(ns, uiSpec, nrow, ncol, outputFunc,
okBtn = okBtn, updateBtn = !autoUpdate, saveBtn = saveBtn,
okBtn = okBtn, updateBtn = !autoUpdate$value, saveBtn = saveBtn,
areaBtns = length(uiSpec$inputs$ind) > 1, border = addBorder,
width = width, height = height)
}
Expand Down Expand Up @@ -248,7 +248,7 @@ MWController <- setRefClass(
input$updateHTML(session)
}
})
if (autoUpdate) renderShinyOutputs()
if (autoUpdate$value) renderShinyOutputs()
}, error = function(e) {catIfDebug("Initialization error"); print(e)})
},

Expand Down Expand Up @@ -283,7 +283,7 @@ MWController <- setRefClass(
}
})

observeEvent(input$.update, controller$updateCharts())
observeEvent(input$.update, controller$updateCharts(), ignoreNULL = !autoUpdate$initBtn)
observeEvent(input$done, onDone(controller))

output$save <- shiny::downloadHandler(
Expand Down
4 changes: 3 additions & 1 deletion R/manipulate_widget.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#' \code{TRUE}, then the graphic is updated only when the user clicks on the
#' update button.
#' @param .saveBtn Should an save button be added to the controls ?
#' @param .updateBtnInit In case of update button. Do you want to render graphics on init ?
#' @param .viewer Controls where the gadget should be displayed. \code{"pane"}
#' corresponds to the Rstudio viewer, \code{"window"} to a dialog window, and
#' \code{"browser"} to an external web browser.
Expand Down Expand Up @@ -221,6 +222,7 @@
#' @export
#'
manipulateWidget <- function(.expr, ..., .updateBtn = FALSE, .saveBtn = TRUE,
.updateBtnInit = FALSE,
.viewer = c("pane", "window", "browser"),
.compare = NULL,
.compareOpts = compareOptions(),
Expand Down Expand Up @@ -254,7 +256,7 @@ manipulateWidget <- function(.expr, ..., .updateBtn = FALSE, .saveBtn = TRUE,
inputs <- initInputs(list(...), env = .env, compare = .compare,
ncharts = .compareOpts$ncharts)
# Initialize controller
controller <- MWController(.expr, inputs, autoUpdate = !.updateBtn,
controller <- MWController(.expr, inputs, autoUpdate = list(value = !.updateBtn, initBtn = .updateBtnInit),
nrow = dims$nrow, ncol = dims$ncol,
returnFunc = .return)

Expand Down
2 changes: 1 addition & 1 deletion man/MWController-class.Rd

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

9 changes: 6 additions & 3 deletions man/manipulateWidget.Rd

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

0 comments on commit 7d55959

Please sign in to comment.