Skip to content

Remove welcome_page() and layout_container_id() #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions R/dash.R
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ Dash <- R6::R6Class(
if (render) private$layout_render() else private$layout_
},
layout = function(...) {
private$layout_ <- if (is.function(..1)) ..1 else list(...)
private$layout_ <- if (is.function(..1)) ..1 else (...)
# render the layout, and then return the rendered layout without printing
invisible(private$layout_render())
},
Expand Down Expand Up @@ -554,22 +554,14 @@ Dash <- R6::R6Class(
dependencies_internal = list(),

# layout stuff
layout_ = welcome_page(),
layout_ = NULL,
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_

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

# make sure we are working with a list of components
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())
# ensure layout is a Dash component or collection of components
layout_ <- private$validate_component(layout_)

# store the layout as a (flattened) vector form since we query the
# vector names several times to verify ID naming (among other things)
Expand Down Expand Up @@ -731,7 +723,7 @@ Dash <- R6::R6Class(
other = other_files_map))
},

componentify = function(x) {
validate_component = function(x) {
if (is.component(x)) return(x)
if (all(vapply(x, is.component, logical(1)))) return(x)
stop("The layout must be a component or a collection of components", call. = FALSE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In python the error we get is:

dash.exceptions.NoLayoutException:
Layout must be a dash component or a function that returns a dash component.

As discussed on slack earlier, seems like the same holds in R, we can't have a list/collection here either. And if this is where you'd see the error if layout was given a function with an invalid return, I'd give exactly the same error message as in Python.

That has knock-on effects - so layout = function(...) { should turn into layout = function(value) {, and this whole validate_component might as well be 🔪 since it'll just be if (!is.component(x)) stop(...)

Expand Down Expand Up @@ -920,7 +912,7 @@ Dash <- R6::R6Class(
# @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)
if (!is.component(layout_)) stop("`layout` must be a Dash component or collection of components", call. = FALSE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case we can actually hit this stop? Doesn't the one in layout_render cover us?

Copy link
Contributor Author

@rpkyle rpkyle Jun 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have trouble seeing where this gets tripped as well; this is leftover code from the early revisions of the package. I suspect it made more sense when we wrapped the layout in an htmlDiv and wanted to ensure the layout was a list.

Here I'm actively trying to avoid that, so it probably does make sense to 🔪 this.

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
16 changes: 0 additions & 16 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ is.state <- function(x) inherits(x, "state")
# components (TODO: this should be exported by dashRtranspile!)
is.component <- function(x) inherits(x, "dash_component")

# layout is really a special type of component
is.layout <- function(x) {
is.component(x) && identical(x[["props"]][["id"]], layout_container_id())
}

layout_container_id <- function() {
"_dashR-layout-container"
}

# retrieve the arguments of a callback function that are dash inputs
callback_inputs <- function(func) {
compact(lapply(formals(func), function(x) {
Expand Down Expand Up @@ -274,13 +265,6 @@ setdiffsym <- function(x, y) {
setdiff(union(x, y), intersect(x, y))
}

welcome_page <- function() {
#dashHtmlComponents::htmlDiv(
# dashHtmlComponents::htmlH2("Welcome to dash!"),
# "If you see this message, you may not have yet specified a layout in your application."
#)
}

stop_report <- function(msg = "") {
stop(
msg, "\n\n",
Expand Down