diff --git a/NAMESPACE b/NAMESPACE index 3cc6fb856..5fc1243c3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,6 +10,7 @@ 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) @@ -21,7 +22,6 @@ 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_a_kmeans.R b/R/tm_a_kmeans.R deleted file mode 100644 index 6aafaab39..000000000 --- a/R/tm_a_kmeans.R +++ /dev/null @@ -1,158 +0,0 @@ -# BASIC SHINY APP - -library(shiny) -ui <- fluidPage( - selectInput("selected", "Variable", choices = names(iris)[-5], selected = names(iris)[1], multiple = TRUE), - numericInput("centers", "bins", 10, min = 1), - tableOutput("table") -) -server <- function(input, output, session) { - data <- reactive(iris[, input$selected, drop = FALSE]) - - clustering_data <- - reactive({ - cbind( - data(), - clusters = kmeans(data(), centers = input$centers)$cluster - ) - }) - - output$table <- renderTable({ - clustering_data() - }) -} - -shinyApp(ui, server) - -# SHINY MODULE - -kmeans_ui <- function(id, data = iris) { - - # pick only numeric - data <- data[vapply(data, is.numeric, logical(1))] - - tagList( - selectInput(NS(id, "selected"), "Variable", choices = names(data), selected = names(data)[1], multiple = TRUE), - numericInput(NS(id, "centers"), "bins", 10, min = 1), - tableOutput(NS(id, "table")) - ) -} - -kmeans_server <- function(id, data= iris) { - moduleServer(id, function(input, output, session) { - dataset <- reactive(data[, input$selected, drop = FALSE]) - - clustering_data <- - reactive({ - cbind( - dataset(), - clusters = kmeans(dataset(), centers = input$centers)$cluster - ) - }) - - output$table <- renderTable({ - clustering_data() - }) - }) -} - -kmeans_app <- function(data = iris) { - ui <- fluidPage( - kmeans_ui("kmeans_mod", data = data) - ) - server <- function(input, output, session) { - kmeans_server("kmeans_mod", data = data) - } - shinyApp(ui, server) -} -library(shiny) -kmeans_app(data = mtcars) -kmeans_app(data = iris) -kmeans_app(data = swiss) - - - -tm_kmeans <- function(label, data= NULL) { - checkmate::assert_character(label) - - module( - label = label, - server = kmeans_server, - ui = kmeans_ui, - ui_args = list(data = data), - server_args = list(data = data), - filters = "all" - ) -} - -library(teal) - -app <- init( - data = mtcars, - modules = tm_kmeans(label = "K-means Clustering"), - header = "Simple app with k-means clustering module" -) - -shinyApp(app$ui, app$server) - -# TEAL - -ui_kmeans_example <- function(id, clustering_vars) { - ns <- NS(id) - teal.widgets::standard_layout( - output = tableOutput(ns("table")), - encoding = div( - teal.transform::data_extract_ui( - id = ns("clustering_vars"), - label = "Variable", - data_extract_spec = clustering_vars - ) - ) - ) -} - -srv_kmeans_example <- function(id, data) { - checkmate::assert_class(data, "tdata") - moduleServer(id, function(input, output, session) { - - clustering_data <- - reactive({ - cbind( - input$data, - clusters = kmeans(input$data[, input$selected], centers = input$centers)$cluster - ) - }) - - output$table <- renderTable({ - clustering_data() - }) - - }) -} - -# tm_kmeans <- function(label) { -# checkmate::assert_character(label) -# -# module( -# label = label, -# server = srv_kmeans_example, -# ui = ui_kmeans_example -# ) -# } -# -# library(teal) -# -# app <- init( -# data = teal_data( -# dataset("IRIS", iris, code = "IRIS <- iris"), -# check = TRUE -# ), -# modules = tm_kmeans( -# label = "K-means Clustering" -# ), -# header = "Simple app with k-means clustering module" -# ) -# -# if (interactive()) { -# shinyApp(app$ui, app$server) -# } diff --git a/R/tm_landing_popup.R b/R/tm_landing_popup.R index c19b9020f..cfbcee433 100644 --- a/R/tm_landing_popup.R +++ b/R/tm_landing_popup.R @@ -1,24 +1,58 @@ #' Landing Popup module #' -#' @description This `teal` module creates a simple landing welcome popup for `teal` applications and -#' can be used in `teal::init(extra_server = )` parameter +#' @description This function creates a simple landing welcome popup for `teal` applications and +#' can be used in a `teal::init(extra_server = )` parameter. +#' +#' @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. +#' +#' @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) +#' } #' -#' @param title tba -#' @param text tba -#' @param button tba -#' @param icon tba #' #' @export -tm_landing_popup <- function(title = NULL, text = NULL, button = NULL, icon = NULL) { +landing_popup <- function(title = NULL, content = NULL, buttons = modalButton("Accept")) { checkmate::assert_string(title, null.ok = TRUE) - checkmate::assert_string(text, null.ok = TRUE) - checkmate::assert_string(button, null.ok = TRUE) - checkmate::assert_string(icon, 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) - shinyalert::shinyalert( - title = title, - text = text, - type = "info", - confirmButtonText = button + showModal( + modalDialog( + title = title, + content, + footer = buttons + ) ) + # div(class="sweet-overlay", tabindex = "-1", style = "opacity: 1.17;display: block;backdrop-filter: blur(10px);") } diff --git a/man/landing_popup.Rd b/man/landing_popup.Rd new file mode 100644 index 000000000..769200a52 --- /dev/null +++ b/man/landing_popup.Rd @@ -0,0 +1,54 @@ +% 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 module} +\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 deleted file mode 100644 index 604dfec5c..000000000 --- a/man/tm_landing_popup.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% 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(title = NULL, text = NULL, button = NULL, icon = NULL) -} -\arguments{ -\item{title}{tba} - -\item{text}{tba} - -\item{button}{tba} - -\item{icon}{tba} -} -\description{ -This \code{teal} module creates a simple landing welcome popup for \code{teal} applications and -can be used in \code{teal::init(extra_server = )} parameter -}