Skip to content

Commit

Permalink
reusing html
Browse files Browse the repository at this point in the history
  • Loading branch information
gogonzo committed Oct 29, 2024
1 parent bd8041a commit a0d2e59
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 21 deletions.
25 changes: 7 additions & 18 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,24 +134,13 @@ report_card_template <- function(title, label, description = NULL, with_filter,
#' @return `TRUE` if validation passes, otherwise `character(1)` or `shiny.tag.list`
#' @keywords internal
check_modules_datanames <- function(modules, datanames) {
check_datanames <- check_modules_datanames_recursive(modules, datanames)
if (length(check_datanames)) {
modules_msg <- sapply(check_datanames, function(mod) {
sprintf(
"%s %s %s missing for module %s.",
if (length(mod$missing_datanames) > 1) "Datasets" else "Dataset",
toString(dQuote(mod$missing_datanames, q = FALSE)),
if (length(mod$missing_datanames) > 1) "are" else "is",
toString(dQuote(mod$label, q = FALSE))
)
})
sprintf(
"%s Datasets available in data: %s",
paste(modules_msg, collapse = "\n"),
toString(dQuote(datanames, q = FALSE))
)
out <- check_modules_datanames_html(modules, datanames)
if (inherits(out, "shiny.tag.list")) {
out_with_ticks <- gsub("<code>|</code>", "`", toString(out))
out_text <- trimws(gsub("<[^<>]+>", "", toString(out_with_ticks)))
gsub("[[:space:]]+", " ", out_text)
} else {
TRUE
out
}
}

Expand All @@ -174,7 +163,7 @@ check_modules_datanames_html <- function(modules,
tags$span(
paste0(
if (length(mod$missing_datanames) > 1) "are missing" else "is missing",
if (show_module_info) sprintf(" for tab '%s'.", mod$label) else "."
if (show_module_info) sprintf(" for module '%s'.", mod$label) else "."
)
)
),
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-init.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ testthat::test_that(
data = teal.data::teal_data(mtcars = mtcars),
modules = list(example_module(datanames = "iris"))
),
"Dataset \"iris\" is missing for module \"example teal module\". Datasets available in data: \"mtcars\""
"Dataset `iris` is missing for module 'example teal module'. Dataset available in data: `mtcars`."
)
}
)
Expand All @@ -77,7 +77,7 @@ testthat::test_that(
data = teal.data::teal_data(mtcars = mtcars),
modules = list(example_module(datanames = c("a", "b")))
),
"Datasets \"a\", \"b\" are missing for module \"example teal module\". Datasets available in data: \"mtcars\""
"Datasets `a` and `b` are missing for module 'example teal module'. Dataset available in data: `mtcars`."
)
}
)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-module_teal.R
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ testthat::describe("srv_teal teal_modules", {
)
)
),
"Datasets missing1 and missing2 are missing for tab 'module_1'. Dataset available in data: mtcars."
"Datasets missing1 and missing2 are missing for module 'module_1'. Dataset available in data: mtcars."
)
}
)
Expand Down

0 comments on commit a0d2e59

Please sign in to comment.