Skip to content

Commit

Permalink
🔨 rename layout_set() to layout(), layout to layout_ (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
rpkyle authored Apr 2, 2019
1 parent 3ff3c62 commit 7dea73f
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions R/dash.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#'
#' @section Methods:
#' \describe{
#' \item{`layout_set(...)`}{
#' \item{`layout(...)`}{
#' Set the layout (i.e., user interface). The layout should be either a
#' collection of dash components (e.g., [coreSlider], [htmlDiv], etc) or
#' a function which returns a collection of components.
Expand Down Expand Up @@ -338,10 +338,10 @@ Dash <- R6::R6Class(
# dash layout methods
# ------------------------------------------------------------------------
layout_get = function(render = TRUE) {
if (render) private$layout_render() else private$layout
if (render) private$layout_render() else private$layout_
},
layout_set = function(...) {
private$layout <- if (is.function(..1)) ..1 else list(...)
layout = function(...) {
private$layout_ <- if (is.function(..1)) ..1 else list(...)
# render the layout, and then return the rendered layout without printing
invisible(private$layout_render())
},
Expand Down Expand Up @@ -437,26 +437,26 @@ Dash <- R6::R6Class(
dependencies_internal = list(),

# layout stuff
layout = welcome_page(),
layout_ = welcome_page(),
layout_ids = NULL,
layout_render = function() {
# assuming private$layout is either a function or a list of components...
layout <- if (is.function(private$layout)) private$layout() else private$layout
layout_ <- if (is.function(private$layout_)) private$layout_() else private$layout_

# accomodate functions that return a single component
if (is.component(layout)) layout <- list(layout)
if (is.component(layout_)) layout_ <- list(layout_)

# make sure we are working with a list of components
layout <- lapply(layout, private$componentify)
layout_ <- lapply(layout_, private$componentify)

# Put the list of components into a container div. I'm pretty sure dash
# requires the layout to be one component, but R folks are used to
# being able to supply "components" to ...
layout <- dashHtmlComponents::htmlDiv(children = layout, id = layout_container_id())
layout_ <- dashHtmlComponents::htmlDiv(children = layout_, id = layout_container_id())

# store the layout as a (flattened) vector form since we query the
# vector names several times to verify ID naming (among other things)
layout_flat <- rapply(layout, I)
layout_flat <- rapply(layout_, I)
layout_nms <- names(layout_flat)

# verify that layout ids are unique
Expand Down Expand Up @@ -521,8 +521,8 @@ Dash <- R6::R6Class(
private$dependencies_internal <- dashR:::.dashR_js_metadata()

# return the computed layout
oldClass(layout) <- c("dash_layout", oldClass(layout))
layout
oldClass(layout_) <- c("dash_layout", oldClass(layout_))
layout_
},

componentify = function(x) {
Expand Down Expand Up @@ -614,8 +614,8 @@ Dash <- R6::R6Class(
# verify that properties attached to output/inputs/state value are valid
# @param layout
# @param component a component (should be a dependency)
validate_dependency <- function(layout, dependency) {
if (!is.layout(layout)) stop("`layout` must be a dash layout object", call. = FALSE)
validate_dependency <- function(layout_, dependency) {
if (!is.layout(layout_)) stop("`layout` must be a dash layout object", call. = FALSE)
if (!is.dependency(dependency)) stop("`dependency` must be a dash dependency object", call. = FALSE)

valid_props <- component_props_given_id(layout, dependency$id)
Expand Down

0 comments on commit 7dea73f

Please sign in to comment.