diff --git a/DESCRIPTION b/DESCRIPTION index 5445548ad3..6821e04503 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -72,7 +72,6 @@ Roxygen: list(markdown = TRUE) RoxygenNote: 7.2.3 Collate: 'data-ddl-utils.R' - 'data-transform_module.R' 'dummy_functions.R' 'get_rcode_utils.R' 'include_css_js.R' diff --git a/NAMESPACE b/NAMESPACE index dc6767b1f6..5ed5025741 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -18,9 +18,6 @@ S3method(ui_nested_tabs,teal_modules) export("%>%") export(TealReportCard) export(as.teal_slices) -export(close_conn) -export(ddl) -export(delayed_data) export(eval_and_mask) export(example_module) export(get_code_tdata) @@ -30,7 +27,6 @@ export(landing_popup_module) export(module) export(modules) export(new_tdata) -export(open_conn) export(report_card_template) export(reporter_previewer_module) export(show_rcode_modal) diff --git a/R/data-ddl-utils.R b/R/data-ddl-utils.R index 3ebd959bd0..09ba28640b 100644 --- a/R/data-ddl-utils.R +++ b/R/data-ddl-utils.R @@ -40,11 +40,6 @@ eval_and_mask <- function(data, data@code[length(data@code)] <- format_expression(.substitute_code(expr = code, env = env_masked)) } - # todo: should it be here or in datanames(data)? - if (length(datanames(data)) == 0) { - datanames(data) <- ls(data@env) - } - data } @@ -66,39 +61,3 @@ eval_and_mask <- function(data, ) ) } - -#' Convenience wrapper for ddl -#' -#' @inheritParams delayed_data -#' @param code (`character` or `language`) -#' @param env_mask (`named list`) -#' @export -ddl <- function(code, env_mask, ui, server) { - # todo: do we want to export this? - delayed_data(ui = ui, server = server, code = code, env_mask = env_mask) -} - -ui_login_and_password <- function(id) { - ns <- NS(id) - actionButton(inputId = ns("submit"), label = "Submit") -} - -srv_login_and_password <- function(id, code, env_mask) { - moduleServer(id, function(input, output, session) { - eventReactive(input$submit, { - eval_and_mask(teal_data(), code = code, env = reactiveValuesToList(input), env_mask = env_mask) - }) - }) -} - - -# todo: to remove before merge ------------- -#' @export -open_conn <- function(username, password) { - if (password != "pass") stop("Invalid credentials. 'pass' is the password") else TRUE -} -#' @export -close_conn <- function(conn) { - message("closed") - return(NULL) -} diff --git a/R/data-transform_module.R b/R/data-transform_module.R deleted file mode 100644 index 51c5912267..0000000000 --- a/R/data-transform_module.R +++ /dev/null @@ -1,47 +0,0 @@ -#' `delayed_data` for `teal_data` -#' -#' Function creates object of class `delayed_data` which allows -#' `teal` app developer to transform `teal_data` object passed to `data` argument in -#' [teal::init()]. This helps in case when app developer wants to use `teal` app -#' where `data` can be influenced by app user. For example, app developer can create -#' `teal` app which allows user to connect to database and then use data from this database. -#' @param ui (`function(id)`) function to create UI -#' @param server (`function(id)`) `shiny` server which returns `teal_data` object wrapped in -#' @param ... (`any`) arguments passed to `server` function. -#' `reactive`. `server` should have `id` argument and exactly the same formals as specified in `...`. -#' @export -delayed_data <- function(ui, server, ...) { - # todo: do we want to export this? - checkmate::assert_function(ui, args = "id") - server_args <- list(...) - if (length(server_args) && is.null(names(server_args))) { - stop("All arguments passed to delayed_data() should be named") - } - - server_formals <- names(formals(server)) - extra_args <- setdiff(names(server_args), server_formals) - if (length(extra_args) > 0 && !"..." %in% server_formals) { - stop( - "Unexpected arguments specified in delayed_data(): ", - toString(extra_args), - "\n arguments specified in `...` should be accepted by the `server` function", - call. = FALSE - ) - } - - extra_formals <- setdiff(server_formals, c("id", names(server_args))) - if (length(extra_formals) > 0) { - stop( - "Missing arguments specified in delayed_data(): ", - toString(extra_formals), - "\n arguments specified in `...` should be the same as in `server` function", - call. = FALSE - ) - } - - x <- list(ui = ui, server = server) - structure(x, - server_args = server_args, - class = c("delayed_data", class(x)) - ) -} diff --git a/R/init.R b/R/init.R index 287d1c175c..6504cc697e 100644 --- a/R/init.R +++ b/R/init.R @@ -115,7 +115,8 @@ init <- function(data = teal_data(), id = character(0)) { logger::log_trace("init initializing teal app with: data ({ class(data)[1] }).") if ( - !inherits(data, c("TealData", "teal_data")) && !test_shiny_module_list(data) + !inherits(data, c("TealData", "teal_data")) && + !(is.list(data) && identical(names(data), c("ui", "server"))) ) { data <- teal.data::to_relational_data(data = data) } diff --git a/R/utils.R b/R/utils.R index 570b3b9256..30a6e0ef1d 100644 --- a/R/utils.R +++ b/R/utils.R @@ -191,13 +191,16 @@ check_filter_datanames <- function(filters, datanames) { test_shiny_module_list <- function(data) { - is.list(data) && identical(names(data), c("ui", "server")) + is.list(data) && + identical(names(data), c("ui", "server")) && + identical(names(formals(data$ui)), "id") && + identical(names(formals(data$server)), "id") } check_shiny_module_list <- function(data) { if (!test_shiny_module_list(data)) { - "`data` should be a list with 'ui' and 'server' elements." + "`data` should be a list with 'ui' and 'server' functions having 'id' argument only." } else { TRUE } diff --git a/man/ddl.Rd b/man/ddl.Rd deleted file mode 100644 index fa14358f23..0000000000 --- a/man/ddl.Rd +++ /dev/null @@ -1,20 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data-ddl-utils.R -\name{ddl} -\alias{ddl} -\title{Convenience wrapper for ddl} -\usage{ -ddl(code, env_mask, ui, server) -} -\arguments{ -\item{code}{(\code{character} or \code{language})} - -\item{env_mask}{(\verb{named list})} - -\item{ui}{(\verb{function(id)}) function to create UI} - -\item{server}{(\verb{function(id)}) \code{shiny} server which returns \code{teal_data} object wrapped in} -} -\description{ -Convenience wrapper for ddl -} diff --git a/man/delayed_data.Rd b/man/delayed_data.Rd deleted file mode 100644 index 10957a9ec0..0000000000 --- a/man/delayed_data.Rd +++ /dev/null @@ -1,23 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/data-transform_module.R -\name{delayed_data} -\alias{delayed_data} -\title{\code{delayed_data} for \code{teal_data}} -\usage{ -delayed_data(ui, server, ...) -} -\arguments{ -\item{ui}{(\verb{function(id)}) function to create UI} - -\item{server}{(\verb{function(id)}) \code{shiny} server which returns \code{teal_data} object wrapped in} - -\item{...}{(\code{any}) arguments passed to \code{server} function. -\code{reactive}. \code{server} should have \code{id} argument and exactly the same formals as specified in \code{...}.} -} -\description{ -Function creates object of class \code{delayed_data} which allows -\code{teal} app developer to transform \code{teal_data} object passed to \code{data} argument in -\code{\link[=init]{init()}}. This helps in case when app developer wants to use \code{teal} app -where \code{data} can be influenced by app user. For example, app developer can create -\code{teal} app which allows user to connect to database and then use data from this database. -}