Skip to content

Commit

Permalink
Feature branch PR (#1253)
Browse files Browse the repository at this point in the history
remove insertUI and make teal_data_module

---------

Signed-off-by: Vedha Viyash <[email protected]>
Signed-off-by: Marcin <[email protected]>
Signed-off-by: André Veríssimo <[email protected]>
Co-authored-by: vedhav <[email protected]>
Co-authored-by: André Veríssimo <[email protected]>
Co-authored-by: m7pr <[email protected]>
Co-authored-by: Vedha Viyash <[email protected]>
Co-authored-by: Marcin <[email protected]>
Co-authored-by: 27856297+dependabot-preview[bot]@users.noreply.github.com <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dony Unardi <[email protected]>
  • Loading branch information
9 people authored Aug 13, 2024
1 parent 8ba7e31 commit 6fc5421
Show file tree
Hide file tree
Showing 111 changed files with 6,122 additions and 3,910 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ vignettes/*.md
inst/doc
tests/testthat/_snaps/**/*.new.md
tests/testthat/_snaps/**/*.new.svg
teal_app.lock
9 changes: 6 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ Imports:
jsonlite,
lifecycle (>= 0.2.0),
logger (>= 0.2.0),
magrittr (>= 1.5),
methods,
promises (>= 1.3.0),
renv (>= 1.0.7),
Expand Down Expand Up @@ -98,20 +97,24 @@ Collate:
'init.R'
'landing_popup_module.R'
'module_bookmark_manager.R'
'module_data_summary.R'
'module_filter_data.R'
'module_filter_manager.R'
'module_init_data.R'
'module_nested_tabs.R'
'module_snapshot_manager.R'
'module_tabs_with_filters.R'
'module_teal.R'
'module_teal_data.R'
'module_teal_with_splash.R'
'module_wunder_bar.R'
'module_transform_data.R'
'reporter_previewer_module.R'
'show_rcode_modal.R'
'tdata.R'
'teal.R'
'teal_data_module.R'
'teal_data_module-eval_code.R'
'teal_data_module-within.R'
'teal_data_utils.R'
'teal_lockfile.R'
'teal_reporter.R'
'teal_slices-store.R'
Expand Down
23 changes: 13 additions & 10 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
S3method(c,teal_slices)
S3method(format,teal_module)
S3method(format,teal_modules)
S3method(get_metadata,default)
S3method(get_metadata,tdata)
S3method(join_keys,tdata)
S3method(print,teal_module)
S3method(print,teal_modules)
S3method(srv_nested_tabs,default)
S3method(srv_nested_tabs,teal_module)
S3method(srv_nested_tabs,teal_modules)
S3method(ui_nested_tabs,default)
S3method(ui_nested_tabs,teal_module)
S3method(ui_nested_tabs,teal_modules)
S3method(srv_teal_module,default)
S3method(srv_teal_module,teal_module)
S3method(srv_teal_module,teal_modules)
S3method(ui_teal_module,default)
S3method(ui_teal_module,shiny.tag)
S3method(ui_teal_module,teal_module)
S3method(ui_teal_module,teal_modules)
S3method(within,teal_data_module)
export("%>%")
export(TealReportCard)
export(as.teal_slices)
export(as_tdata)
Expand All @@ -31,10 +29,13 @@ export(new_tdata)
export(report_card_template)
export(reporter_previewer_module)
export(show_rcode_modal)
export(srv_teal)
export(srv_teal_with_splash)
export(tdata2env)
export(teal_data_module)
export(teal_slices)
export(teal_transform_module)
export(ui_teal)
export(ui_teal_with_splash)
export(validate_has_data)
export(validate_has_elements)
Expand All @@ -47,7 +48,9 @@ export(validate_one_row_per_id)
import(shiny)
import(teal.data)
import(teal.slice)
importFrom(magrittr,"%>%")
importFrom(methods,new)
importFrom(methods,setMethod)
importFrom(shiny,reactiveVal)
importFrom(shiny,reactiveValues)
importFrom(stats,setNames)
importMethodsFrom(teal.code,eval_code)
22 changes: 16 additions & 6 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
# teal 0.15.2.9050

### Enhancement
* Provided progress bar for modules loading and data filtering during teal app startup.

### New features

* Possibility to download lockfile to restore app session for reproducibility.
* Possible to call `ui_teal` and `srv_teal` directly in any application by delivering `data` argument as a `reactive` returning `teal_data` object. #669
* Introduced `teal_transform_module` to provide a way to interactively modify data delivered to `teal_module`'s `server`. #1228
* Introduced a new argument `once = FALSE` in `teal_data_module` to possibly reload data during a run time.
* Possibility to download lockfile to restore app session for reproducibility. #479

### Miscellaneous
* Filter mapping display is no longer coupled to the snapshot manager.

### Breaking changes

* The `landing_popup_module()` needs to be passed as the `landing_popup` argument of `init` instead of being passed as a module of the `modules` argument of `init`.
* `teal` no longer re-export `%>%`. Please load `library(magrittr)` instead or use `|>` from `base`.

### Enhancement

* Enhanced a system of data validation and a display of error messages.
* Easier way of to call `javascript` events by setting `$(document).ready(function() { ... })`. #1114
* Provided progress bar for modules loading and data filtering during teal app startup.
* Filter mapping display has a separate icon in the tab.

# teal 0.15.2

Expand Down
122 changes: 89 additions & 33 deletions R/TealAppDriver.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
#' @description
#' Initialize a `TealAppDriver` object for testing a `teal` application.
#'
#' @param data,modules,filter,title,header,footer arguments passed to `init`
#' @param data,modules,filter,title,header,footer,landing_popup arguments passed to `init`
#' @param timeout (`numeric`) Default number of milliseconds for any timeout or
#' timeout_ parameter in the `TealAppDriver` class.
#' Defaults to 20s.
Expand All @@ -45,6 +45,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
title = build_app_title(),
header = tags$p(),
footer = tags$p(),
landing_popup = NULL,
timeout = rlang::missing_arg(),
load_timeout = rlang::missing_arg(),
...) {
Expand All @@ -57,7 +58,8 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
filter = filter,
title = title,
header = header,
footer = footer
footer = footer,
landing_popup = landing_popup,
)

# Default timeout is hardcoded to 4s in shinytest2:::resolve_timeout
Expand Down Expand Up @@ -166,13 +168,11 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
navigate_teal_tab = function(tabs) {
checkmate::check_character(tabs, min.len = 1)
for (tab in tabs) {
root <- "root"
self$set_input(
sprintf("teal-main_ui-%s-active_tab", root),
"teal-teal_modules-active_tab",
get_unique_labels(tab),
wait_ = FALSE
)
root <- sprintf("%s-%s", private$modules$label, get_unique_labels(tab))
}
self$wait_for_idle()
private$set_active_ns()
Expand Down Expand Up @@ -229,6 +229,26 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
private$ns$filter_panel
},
#' @description
#' Get the active shiny name space for interacting with the data-summary panel.
#'
#' @return (`string`) The active shiny name space of the data-summary component.
active_data_summary_ns = function() {
if (identical(private$ns$data_summary, character(0))) {
private$set_active_ns()
}
private$ns$data_summary
},
#' @description
#' Get the active shiny name space bound with a custom `element` name.
#'
#' @param element `character(1)` custom element name.
#'
#' @return (`string`) The active shiny name space of the component bound with the input `element`.
active_data_summary_element = function(element) {
checkmate::assert_string(element)
sprintf("#%s-%s", self$active_data_summary_ns(), element)
},
#' @description
#' Get the input from the module in the `teal` app.
#' This function will only access inputs from the name space of the current active teal module.
#'
Expand Down Expand Up @@ -262,9 +282,10 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
get_active_module_table_output = function(table_id, which = 1) {
checkmate::check_number(which, lower = 1)
checkmate::check_string(table_id)
table <- self$active_module_element(table_id) %>%
self$get_html_rvest() %>%
rvest::html_table(fill = TRUE)
table <- rvest::html_table(
self$get_html_rvest(self$active_module_element(table_id)),
fill = TRUE
)
if (length(table) == 0) {
data.frame()
} else {
Expand Down Expand Up @@ -310,19 +331,37 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
#' Get the active datasets that can be accessed via the filter panel of the current active teal module.
get_active_filter_vars = function() {
displayed_datasets_index <- self$is_visible(
sprintf("#%s-active-filter_active_vars_contents > span", self$active_filters_ns())
sprintf("#%s-filters-filter_active_vars_contents > span", self$active_filters_ns())
)

available_datasets <- self$get_text(
sprintf(
"#%s-active-filter_active_vars_contents .filter_panel_dataname",
"#%s-filters-filter_active_vars_contents .filter_panel_dataname",
self$active_filters_ns()
)
)

available_datasets[displayed_datasets_index]
},
#' @description
#' Get the active data summary table
#' @return `data.frame`
get_active_data_summary_table = function() {
summary_table <- rvest::html_table(
self$get_html_rvest(self$active_data_summary_element("table")),
fill = TRUE
)[[1]]

col_names <- unlist(summary_table[1, ], use.names = FALSE)
summary_table <- summary_table[-1, ]
colnames(summary_table) <- col_names
if (nrow(summary_table) > 0) {
summary_table
} else {
NULL
}
},
#' @description
#' Test if `DOM` elements are visible on the page with a JavaScript call.
#' @param selector (`character(1)`) `CSS` selector to check visibility.
#' A `CSS` id will return only one element if the UI is well formed.
Expand Down Expand Up @@ -371,14 +410,17 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
active_filters <- lapply(
datasets,
function(x) {
var_names <- self$get_text(
sprintf(
"#%s-active-%s-filters .filter-card-varname",
self$active_filters_ns(),
x
var_names <- gsub(
pattern = "\\s",
replacement = "",
self$get_text(
sprintf(
"#%s-filters-%s .filter-card-varname",
self$active_filters_ns(),
x
)
)
) %>%
gsub(pattern = "\\s", replacement = "")
)
structure(
lapply(var_names, private$get_active_filter_selection, dataset_name = x),
names = var_names
Expand All @@ -402,10 +444,19 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
add_filter_var = function(dataset_name, var_name, ...) {
checkmate::check_string(dataset_name)
checkmate::check_string(var_name)
private$set_active_ns()
self$click(
selector = sprintf(
"#%s-filters-%s-add_filter_icon",
private$ns$filter_panel,
dataset_name
)
)
self$set_input(
sprintf(
"%s-add-%s-filter-var_to_add",
self$active_filters_ns(),
"%s-filters-%s-%s-filter-var_to_add",
private$ns$filter_panel,
dataset_name,
dataset_name
),
var_name,
Expand Down Expand Up @@ -468,7 +519,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
checkmate::check_string(input)

input_id_prefix <- sprintf(
"%s-active-%s-filter-%s_%s-inputs",
"%s-filters-%s-filter-%s_%s-inputs",
self$active_filters_ns(),
dataset_name,
dataset_name,
Expand All @@ -492,7 +543,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.

# Generate correct namespace
slices_input_id <- sprintf(
"%s-active-%s-filter-%s_%s-inputs-%s",
"%s-filters-%s-filter-%s_%s-inputs-%s",
self$active_filters_ns(),
dataset_name,
dataset_name,
Expand Down Expand Up @@ -542,9 +593,10 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
#'
#' @return The `character` vector.
get_attr = function(selector, attribute) {
self$get_html_rvest("html") %>%
rvest::html_nodes(selector) %>%
rvest::html_attr(attribute)
rvest::html_attr(
rvest::html_nodes(self$get_html_rvest("html"), selector),
attribute
)
},
#' @description
#' Wrapper around `get_html` that passes the output directly to `rvest::read_html`.
Expand Down Expand Up @@ -602,14 +654,13 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
all_inputs <- self$get_values()$input
active_tab_inputs <- all_inputs[grepl("-active_tab$", names(all_inputs))]

tab_ns <- lapply(names(active_tab_inputs), function(name) {
tab_ns <- unlist(lapply(names(active_tab_inputs), function(name) {
gsub(
pattern = "-active_tab$",
replacement = sprintf("-%s", active_tab_inputs[[name]]),
name
)
}) %>%
unlist()
}))
active_ns <- tab_ns[1]
if (length(tab_ns) > 1) {
for (i in 2:length(tab_ns)) {
Expand All @@ -621,11 +672,16 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
}
private$ns$module <- sprintf("%s-%s", active_ns, "module")

component <- "filter_panel"
if (!is.null(self$get_html(sprintf("#teal-main_ui-%s", component)))) {
private$ns[[component]] <- sprintf("teal-main_ui-%s", component)
} else {
private$ns[[component]] <- sprintf("%s-module_%s", active_ns, component)
components <- c("filter_panel", "data_summary")
for (component in components) {
if (
!is.null(self$get_html(sprintf("#%s-%s-panel", active_ns, component))) ||
!is.null(self$get_html(sprintf("#%s-%s-table", active_ns, component)))
) {
private$ns[[component]] <- sprintf("%s-%s", active_ns, component)
} else {
private$ns[[component]] <- sprintf("%s-module_%s", active_ns, component)
}
}
},
# @description
Expand All @@ -639,7 +695,7 @@ TealAppDriver <- R6::R6Class( # nolint: object_name.
checkmate::check_string(dataset_name)
checkmate::check_string(var_name)
input_id_prefix <- sprintf(
"%s-active-%s-filter-%s_%s-inputs",
"%s-filters-%s-filter-%s_%s-inputs",
self$active_filters_ns(),
dataset_name,
dataset_name,
Expand Down
Loading

0 comments on commit 6fc5421

Please sign in to comment.