Skip to content

Commit

Permalink
layout: support conditional UI (if statements) by allowing NULL in th…
Browse files Browse the repository at this point in the history
…e UI
  • Loading branch information
daattali committed Aug 24, 2021
1 parent 806d344 commit 6396740
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions R/dash_app.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ add_script <- function(app, script) {
#' app <- dash_app()
#'
#' app %>% set_layout("hello", "Dash")
#' app %>% set_layout(htmlDiv("hello"), "Dash")
#' app %>% set_layout(list(htmlDiv("hello"), "Dash"))
#' app %>% set_layout(htmlDiv(children = list(htmlDiv("hello"), "Dash")))
#' app %>% set_layout(div("hello"), "Dash")
#' app %>% set_layout(list(div("hello"), "Dash"))
#' app %>% set_layout("Conditional UI using an if statement: ",
#' if (TRUE) "rendered",
#' if (FALSE) "not rendered")
#' app %>% set_layout(function() { htmlDiv(children = list(htmlDiv("hello"), "Dash")) })
#' @export
set_layout <- function(app, ...) {
Expand Down
2 changes: 2 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ componentify <- function(x) {
dashHtmlComponents::htmlDiv(children = lapply(x, componentify))
} else if (length(x) == 1) {
dashHtmlComponents::htmlSpan(children = x)
} else if (is.null(x)) {
return(NULL)
} else {
stop("dash2: layout must be a dash component or list of dash components", call. = FALSE)
}
Expand Down
8 changes: 5 additions & 3 deletions man/set_layout.Rd

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

0 comments on commit 6396740

Please sign in to comment.