Skip to content

Commit

Permalink
move teal_module_data to data
Browse files Browse the repository at this point in the history
before splitting ddl and shiny modules
  • Loading branch information
gogonzo committed Nov 1, 2023
1 parent 8bca4dd commit 0fbfdab
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
6 changes: 4 additions & 2 deletions R/init.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ 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"))) {
if (!inherits(data, c("TealData", "teal_data", "teal_module_data"))) {
data <- teal.data::to_relational_data(data = data)
}

checkmate::assert_multi_class(data, c("TealData", "teal_data"))
checkmate::assert_multi_class(data, c("TealData", "teal_data", "teal_module_data"))
checkmate::assert_multi_class(modules, c("teal_module", "list", "teal_modules"))
checkmate::assert_string(title, null.ok = TRUE)
checkmate::assert(
Expand Down Expand Up @@ -147,6 +147,8 @@ init <- function(data = teal_data(),
hashables <- mget(c("data", "modules"))
hashables$data <- if (inherits(hashables$data, "teal_data")) {
as.list(hashables$data@env)
} else if (inherits(data, "teal_module_data")) {
# what?
} else if (hashables$data$is_pulled()) {
sapply(get_dataname(hashables$data), simplify = FALSE, function(dn) {
hashables$data$get_dataset(dn)$get_raw_data()
Expand Down
22 changes: 8 additions & 14 deletions R/module_teal_with_splash.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@ ui_teal_with_splash <- function(id,
title,
header = tags$p("Add Title Here"),
footer = tags$p("Add Footer Here")) {
checkmate::assert_multi_class(data, c("TealDataAbstract", "teal_data"))
checkmate::assert_multi_class(data, c("TealDataAbstract", "teal_data", "teal_module_data"))
ns <- NS(id)

data_module <- extract_module(modules, "teal_module_data")[[1]]

# Startup splash screen for delayed loading
# We use delayed loading in all cases, even when the data does not need to be fetched.
# This has the benefit that when filtering the data takes a lot of time initially, the
# Shiny app does not time out.

splash_ui <- if (length(data_module)) {
data_module$ui(ns("data"))
splash_ui <- if (inherits(data, "teal_module_data")) {
data$ui(ns("data"))
} else if (inherits(data, "teal_data")) {
div()
} else if (inherits(data, "TealDataAbstract") && teal.data::is_pulled(data)) {
Expand Down Expand Up @@ -62,26 +60,22 @@ ui_teal_with_splash <- function(id,
#' If data is not loaded yet, `reactive` returns `NULL`.
#' @export
srv_teal_with_splash <- function(id, data, modules, filter = teal_slices()) {
checkmate::assert_multi_class(data, c("TealDataAbstract", "teal_data"))
checkmate::assert_multi_class(data, c("TealDataAbstract", "teal_data", "teal_module_data"))
moduleServer(id, function(input, output, session) {
logger::log_trace("srv_teal_with_splash initializing module with data { toString(get_dataname(data))}.")

if (getOption("teal.show_js_log", default = FALSE)) {
shinyjs::showLog()
}

data_module <- extract_module(modules, "teal_module_data")
if (length(data_module) > 1L) stop("Only one `teal_module_data` can be used.")
modules <- drop_module(modules, "teal_module_data")

# raw_data contains teal_data object
# either passed to teal::init or returned from ddl
raw_data <- if (length(data_module)) {
raw_data <- if (inherits(data, "teal_module_data")) {
ddl_out <- do.call(
data_module[[1]]$server,
data$server,
c(
list(id = "data", data = data),
data_module[[1]]$server_args
list(id = "data"),
data$server_args
)
)
} else if (inherits(data, "teal_data")) {
Expand Down

0 comments on commit 0fbfdab

Please sign in to comment.