From cdefd9fa70c074328b53775228b8022b27200014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 11 Aug 2023 12:03:03 +0100 Subject: [PATCH 1/7] fix: add table to distribution module in show-r-code --- R/tm_g_distribution.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/R/tm_g_distribution.R b/R/tm_g_distribution.R index b6c32d019..bf1801c5b 100644 --- a/R/tm_g_distribution.R +++ b/R/tm_g_distribution.R @@ -648,7 +648,9 @@ srv_distribution <- function(id, ) } - qenv + qenv %>% + # used to display table when running show-r-code code + teal.code::eval_code(quote(summary_table)) }) # distplot qenv ---- @@ -1141,7 +1143,9 @@ srv_distribution <- function(id, ) ) } - qenv + qenv %>% + # used to display table when running show-r-code code + teal.code::eval_code(quote(test_stats)) } ) From 985a212d80ef98dd6dc31a83ca5c54cae5a96b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 11 Aug 2023 12:03:54 +0100 Subject: [PATCH 2/7] fix: add table to outlier module in show-r-code --- R/tm_outliers.R | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/R/tm_outliers.R b/R/tm_outliers.R index 28f06fd33..2db6ae19c 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -313,6 +313,9 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, sum(is.na(ANL[[outlier_var]])) }) + # Used to create outlier table and the dropdown with additional columns + dataname_first <- names(data)[[1]] + common_code_q <- reactive({ shiny::req(iv_r()$is_valid()) @@ -405,7 +408,6 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ungroup_expr %>% # styler: off dplyr::filter(is_outlier | is_outlier_selected) %>% dplyr::select(-is_outlier) - ANL_OUTLIER # used to display table when running show-r-code code }, env = list( calculate_outliers = if (method == "IQR") { @@ -456,6 +458,29 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, remove_pipe_null() ) + # ANL_OUTLIER_EXTENDED is the base table + qenv <- teal.code::eval_code( + qenv, + substitute( + expr = { + ANL_OUTLIER_EXTENDED <- dplyr::left_join( + ANL_OUTLIER, + dplyr::select( + dataname, + dplyr::setdiff(names(dataname), dplyr::setdiff(names(ANL_OUTLIER), join_keys)) + ), + by = join_keys + ) + }, + env = list( + dataname = as.name(dataname_first), + join_keys = as.character(get_join_keys(data)$get(dataname_first)[[dataname_first]]) + ) + ) + ) %>% + # used to display table when running show-r-code code + teal.code::eval_code(quote(ANL_OUTLIER_EXTENDED[ANL_OUTLIER_EXTENDED$is_outlier_selected, ])) + if (length(categorical_var) > 0) { qenv <- teal.code::eval_code( qenv, @@ -933,9 +958,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, brushing = TRUE ) - dataname <- names(data)[[1]] - - choices <- teal.transform::variable_choices(data[[dataname]]()) + choices <- teal.transform::variable_choices(data[[dataname_first]]()) observeEvent(common_code_q(), { ANL_OUTLIER <- common_code_q()[["ANL_OUTLIER"]] # nolint @@ -955,6 +978,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, categorical_var <- as.vector(merged$anl_input_r()$columns_source$categorical_var) ANL_OUTLIER <- common_code_q()[["ANL_OUTLIER"]] # nolint + ANL_OUTLIER_EXTENDED <- common_code_q()[["ANL_OUTLIER_EXTENDED"]] # nolint ANL <- common_code_q()[["ANL"]] # nolint plot_brush <- if (tab == "Boxplot") { boxplot_r() @@ -1026,12 +1050,12 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, } display_table$is_outlier_selected <- NULL - keys <- get_join_keys(data)$get(dataname)[[dataname]] - datas <- data[[dataname]]() + ANL_OUTLIER_EXTENDED$is_outlier_selected <- NULL + # Extend the brushed ANL_OUTLIER with additional columns dplyr::left_join( display_table, - dplyr::select(datas, dplyr::setdiff(names(datas), dplyr::setdiff(names(display_table), keys))), - by = keys + ANL_OUTLIER_EXTENDED, + by = names(display_table) ) %>% dplyr::select(union(names(display_table), input$table_ui_columns)) }, From 9089126131f398aeb290465d8d825b8e048ef7ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 11 Aug 2023 12:52:06 +0100 Subject: [PATCH 3/7] fix: add table to scatterplot module in show-r-code --- R/tm_g_scatterplot.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/tm_g_scatterplot.R b/R/tm_g_scatterplot.R index 029f57071..f7aea4ff2 100644 --- a/R/tm_g_scatterplot.R +++ b/R/tm_g_scatterplot.R @@ -475,7 +475,8 @@ srv_g_scatterplot <- function(id, anl_merged_q <- reactive({ req(anl_merged_input()) teal.code::new_qenv(tdata2env(data), code = get_code_tdata(data)) %>% - teal.code::eval_code(as.expression(anl_merged_input()$expr)) + teal.code::eval_code(as.expression(anl_merged_input()$expr)) %>% + teal.code::eval_code(quote(ANL)) # used to display table when running show-r-code code }) merged <- list( From a4e573d90424b62c024e625b15f5c83780d9d46e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Fri, 11 Aug 2023 14:05:39 +0100 Subject: [PATCH 4/7] chore: correct linter error --- R/tm_outliers.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/tm_outliers.R b/R/tm_outliers.R index 2db6ae19c..4f9221c4e 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -463,7 +463,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, qenv, substitute( expr = { - ANL_OUTLIER_EXTENDED <- dplyr::left_join( + ANL_OUTLIER_EXTENDED <- dplyr::left_join(# nolint object_name_linter ANL_OUTLIER, dplyr::select( dataname, @@ -1050,11 +1050,11 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, } display_table$is_outlier_selected <- NULL - ANL_OUTLIER_EXTENDED$is_outlier_selected <- NULL + # Extend the brushed ANL_OUTLIER with additional columns dplyr::left_join( display_table, - ANL_OUTLIER_EXTENDED, + dplyr::select(ANL_OUTLIER_EXTENDED, -"is_outlier_selected"), by = names(display_table) ) %>% dplyr::select(union(names(display_table), input$table_ui_columns)) From 8afbd414a5ed704740f4cb1a8d58b20a29ee6bb7 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 11 Aug 2023 13:08:47 +0000 Subject: [PATCH 5/7] [skip actions] Restyle files --- R/tm_outliers.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/tm_outliers.R b/R/tm_outliers.R index 4f9221c4e..6ec507b6e 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -463,7 +463,7 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, qenv, substitute( expr = { - ANL_OUTLIER_EXTENDED <- dplyr::left_join(# nolint object_name_linter + ANL_OUTLIER_EXTENDED <- dplyr::left_join( # nolint object_name_linter ANL_OUTLIER, dplyr::select( dataname, From df6e127b77638c88b79480a0a55334158898383b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Wed, 16 Aug 2023 11:24:29 +0200 Subject: [PATCH 6/7] chore: feedback from review to move print code --- R/tm_g_distribution.R | 5 +---- R/tm_outliers.R | 6 +++--- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/R/tm_g_distribution.R b/R/tm_g_distribution.R index bf1801c5b..2c7c6598d 100644 --- a/R/tm_g_distribution.R +++ b/R/tm_g_distribution.R @@ -638,6 +638,7 @@ srv_distribution <- function(id, sd = round(stats::sd(dist_var_name, na.rm = TRUE), roundn), count = dplyr::n() ) + summary_table # used to display table when running show-r-code code }, env = list( dist_var_name = dist_var_name, @@ -647,10 +648,6 @@ srv_distribution <- function(id, ) ) } - - qenv %>% - # used to display table when running show-r-code code - teal.code::eval_code(quote(summary_table)) }) # distplot qenv ---- diff --git a/R/tm_outliers.R b/R/tm_outliers.R index 6ec507b6e..dbeb29ea0 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -471,15 +471,15 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ), by = join_keys ) + # used to display table when running show-r-code code + ANL_OUTLIER_EXTENDED[ANL_OUTLIER_EXTENDED$is_outlier_selected, ] }, env = list( dataname = as.name(dataname_first), join_keys = as.character(get_join_keys(data)$get(dataname_first)[[dataname_first]]) ) ) - ) %>% - # used to display table when running show-r-code code - teal.code::eval_code(quote(ANL_OUTLIER_EXTENDED[ANL_OUTLIER_EXTENDED$is_outlier_selected, ])) + ) if (length(categorical_var) > 0) { qenv <- teal.code::eval_code( From 77be5b3d43e0d85b6ced0b9f816b2b88e5757c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Ver=C3=ADssimo?= <211358+averissimo@users.noreply.github.com> Date: Wed, 16 Aug 2023 13:19:32 +0200 Subject: [PATCH 7/7] fix: only print columns that are shown in UI (show-r-code) --- R/tm_outliers.R | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/R/tm_outliers.R b/R/tm_outliers.R index dbeb29ea0..fba0c5ceb 100644 --- a/R/tm_outliers.R +++ b/R/tm_outliers.R @@ -471,8 +471,6 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, ), by = join_keys ) - # used to display table when running show-r-code code - ANL_OUTLIER_EXTENDED[ANL_OUTLIER_EXTENDED$is_outlier_selected, ] }, env = list( dataname = as.name(dataname_first), @@ -864,13 +862,31 @@ srv_outliers <- function(id, data, reporter, filter_panel_api, outlier_var, final_q <- reactive({ req(input$tabs) tab_type <- input$tabs - if (tab_type == "Boxplot") { + result_q <- if (tab_type == "Boxplot") { boxplot_q() } else if (tab_type == "Density Plot") { density_plot_q() } else if (tab_type == "Cumulative Distribution Plot") { cumulative_plot_q() } + # used to display table when running show-r-code code + # added after the plots so that a change in selected columns doesn't affect + # brush selection. + teal.code::eval_code( + result_q, + substitute( + expr = { + columns_index <- union( + setdiff(names(ANL_OUTLIER), "is_outlier_selected"), + table_columns + ) + ANL_OUTLIER_EXTENDED[ANL_OUTLIER_EXTENDED$is_outlier_selected, columns_index] + }, + env = list( + table_columns = input$table_ui_columns + ) + ) + ) }) # slider text