diff --git a/NAMESPACE b/NAMESPACE index 5fc1243c3..3cc6fb856 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,7 +10,6 @@ S3method(create_sparklines,logical) S3method(create_sparklines,numeric) export(add_facet_labels) export(get_scatterplotmatrix_stats) -export(landing_popup) export(tm_a_pca) export(tm_a_regression) export(tm_data_table) @@ -22,6 +21,7 @@ export(tm_g_distribution) export(tm_g_response) export(tm_g_scatterplot) export(tm_g_scatterplotmatrix) +export(tm_landing_popup) export(tm_missing_data) export(tm_outliers) export(tm_t_crosstable) diff --git a/R/tm_landing_popup.R b/R/tm_landing_popup.R index f83de6f62..17cbdf797 100644 --- a/R/tm_landing_popup.R +++ b/R/tm_landing_popup.R @@ -1,23 +1,27 @@ -#' Landing Popup +#' Landing Popup Module #' -#' @description This function creates a simple landing welcome popup for `teal` applications and -#' can be used in a `teal::init(extra_server = )` parameter. +#' @description This module creates a simple landing welcome popup for `teal` applications. #' +#' @details It is recommended to pass this module as the first one in `teal::init(modules = )`. +#' +#' @inheritParams teal::module #' @param title `character(1)` the text to be displayed as a title of the popup. #' @param content `character(1)` the content of the popup. Passed to `...` of `shiny::modalDialog`. Can be a `character` #' or a text input control (like `textInput`) or a list of `shiny` tags. See examples. #' @param buttons `shiny` tag or a list of tags (`tagList`). Typically a `modalButton` or `actionButton`. See examples. #' +#' @return A `teal` module to be used in `teal` applications. +#' #' @examples #' app1 <- teal::init( #' data = teal.data::dataset("iris", iris), #' modules = teal::modules( -#' teal.modules.general::tm_front_page("A") -#' ), -#' extra_server = teal.modules.general::landing_popup( -#' title = "Welcome", -#' content = "A place for the welcome message or a disclaimer statement.", -#' buttons = modalButton("Proceed") +#' teal.modules.general::tm_landing_popup( +#' title = "Welcome", +#' content = "A place for the welcome message or a disclaimer statement.", +#' buttons = modalButton("Proceed") +#' ), +#' teal.modules.general::tm_front_page() #' ) #' ) #' if (interactive()) { @@ -27,15 +31,15 @@ #' app2 <- teal::init( #' data = teal.data::dataset("iris", iris), #' modules = teal::modules( -#' teal.modules.general::tm_front_page("A") -#' ), -#' extra_server = teal.modules.general::landing_popup( -#' title = "Welcome", -#' content = div(tags$b("A place for the welcome message or a disclaimer statement.", style = "color: red;")), -#' buttons = tagList( -#' modalButton("Proceed"), -#' actionButton("close", "Read more", onclick = "window.open('http://google.com', '_blank')") -#' ) +#' teal.modules.general::tm_landing_popup( +#' title = "Welcome", +#' content = div(tags$b("A place for the welcome message or a disclaimer statement.", style = "color: red;")), +#' buttons = tagList( +#' modalButton("Proceed"), +#' actionButton("close", "Read more", onclick = "window.open('http://google.com', '_blank')") +#' ) +#' ), +#' teal.modules.general::tm_front_page() #' ) #' ) #' @@ -44,20 +48,44 @@ #' } #' #' @export -landing_popup <- function(title = NULL, content = NULL, buttons = modalButton("Accept")) { - checkmate::assert_string(title, null.ok = TRUE) - checkmate::assert_multi_class( - content, - classes = c("character", "shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE - ) - checkmate::assert_multi_class(buttons, classes = c("shiny.tag", "shiny.tag.list"), null.ok = TRUE) - - showModal( - modalDialog( - id = "landingpopup", - title = title, +tm_landing_popup <- + function( + label = "Landing popup", + title = NULL, + content = NULL, + buttons = modalButton("Accept") + ) { + checkmate::assert_string(label) + checkmate::assert_string(title, null.ok = TRUE) + checkmate::assert_multi_class( content, - footer = buttons + classes = c("character", "shiny.tag", "shiny.tag.list", "html"), null.ok = TRUE ) + checkmate::assert_multi_class(buttons, classes = c("shiny.tag", "shiny.tag.list"), null.ok = TRUE) + + logger::log_info("Initializing tm_landing_popup") + + module( + label = label, + server = srv_landing_popup, + ui = ui_landing_popup, + ui_args = NULL, + server_args = list(title = title, content = content, buttons = buttons), + datanames = NULL ) } + +srv_landing_popup <- function(id, title, content, buttons) { + moduleServer(id, function(input, output, session) { + showModal( + modalDialog( + id = "landingpopup", + title = title, + content, + footer = buttons + ) + ) + }) +} + +ui_landing_popup <- function(id, ...) {NULL} diff --git a/_pkgdown.yml b/_pkgdown.yml index abcfc6ec6..ec36b1c74 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -27,7 +27,6 @@ reference: - title: General functionality modules contents: - matches('tm_[a-z][a-z]') - - landing_popup - title: Modules for tables contents: diff --git a/man/landing_popup.Rd b/man/landing_popup.Rd deleted file mode 100644 index 880d070f4..000000000 --- a/man/landing_popup.Rd +++ /dev/null @@ -1,56 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/tm_landing_popup.R -\name{landing_popup} -\alias{landing_popup} -\title{Landing Popup} -\usage{ -landing_popup(title = NULL, content = NULL, buttons = modalButton("Accept")) -} -\arguments{ -\item{title}{\code{character(1)} the text to be displayed as a title of the popup.} - -\item{content}{\code{character(1)} the content of the popup. Passed to \code{...} of \code{shiny::modalDialog}. Can be a \code{character} -or a text input control (like \code{textInput}) or a list of \code{shiny} tags. See examples.} - -\item{buttons}{\code{shiny} tag or a list of tags (\code{tagList}). Typically a \code{modalButton} or \code{actionButton}. See examples.} -} -\description{ -This function creates a simple landing welcome popup for \code{teal} applications and -can be used in a \code{teal::init(extra_server = )} parameter. -} -\examples{ -app1 <- teal::init( - data = teal.data::dataset("iris", iris), - modules = teal::modules( - teal.modules.general::tm_front_page("A") - ), - extra_server = teal.modules.general::landing_popup( - title = "Welcome", - content = "A place for the welcome message or a disclaimer statement.", - buttons = modalButton("Proceed") - ) -) -if (interactive()) { - shinyApp(app1$ui, app1$server) -} - -app2 <- teal::init( - data = teal.data::dataset("iris", iris), - modules = teal::modules( - teal.modules.general::tm_front_page("A") - ), - extra_server = teal.modules.general::landing_popup( - title = "Welcome", - content = div(tags$b("A place for the welcome message or a disclaimer statement.", style = "color: red;")), - buttons = tagList( - modalButton("Proceed"), - actionButton("close", "Read more", onclick = "window.open('http://google.com', '_blank')") - ) - ) -) - -if (interactive()) { - shinyApp(app2$ui, app2$server) -} - -} diff --git a/man/tm_landing_popup.Rd b/man/tm_landing_popup.Rd new file mode 100644 index 000000000..229919ea4 --- /dev/null +++ b/man/tm_landing_popup.Rd @@ -0,0 +1,69 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/tm_landing_popup.R +\name{tm_landing_popup} +\alias{tm_landing_popup} +\title{Landing Popup Module} +\usage{ +tm_landing_popup( + label = "Landing popup", + title = NULL, + content = NULL, + buttons = modalButton("Accept") +) +} +\arguments{ +\item{label}{(\code{character(1)}) Label shown in the navigation item for the module. Any label possible except +\code{"global_filters"} - read more in \code{mapping} argument of \link[teal]{teal_slices}.} + +\item{title}{\code{character(1)} the text to be displayed as a title of the popup.} + +\item{content}{\code{character(1)} the content of the popup. Passed to \code{...} of \code{shiny::modalDialog}. Can be a \code{character} +or a text input control (like \code{textInput}) or a list of \code{shiny} tags. See examples.} + +\item{buttons}{\code{shiny} tag or a list of tags (\code{tagList}). Typically a \code{modalButton} or \code{actionButton}. See examples.} +} +\value{ +A \code{teal} module to be used in \code{teal} applications. +} +\description{ +This module creates a simple landing welcome popup for \code{teal} applications. +} +\details{ +It is recommended to pass this module as the first one in \code{teal::init(modules = )}. +} +\examples{ +app1 <- teal::init( + data = teal.data::dataset("iris", iris), + modules = teal::modules( + teal.modules.general::tm_landing_popup( + title = "Welcome", + content = "A place for the welcome message or a disclaimer statement.", + buttons = modalButton("Proceed") + ), + teal.modules.general::tm_front_page() + ) +) +if (interactive()) { + shinyApp(app1$ui, app1$server) +} + +app2 <- teal::init( + data = teal.data::dataset("iris", iris), + modules = teal::modules( + teal.modules.general::tm_landing_popup( + title = "Welcome", + content = div(tags$b("A place for the welcome message or a disclaimer statement.", style = "color: red;")), + buttons = tagList( + modalButton("Proceed"), + actionButton("close", "Read more", onclick = "window.open('http://google.com', '_blank')") + ) + ), + teal.modules.general::tm_front_page() + ) +) + +if (interactive()) { + shinyApp(app2$ui, app2$server) +} + +}