Skip to content

Commit 524da4c

Browse files
committed
chore: cleanup and remove warning
1 parent 314e06c commit 524da4c

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

R/tm_missing_data.R

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,21 +1055,19 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
10551055
function(x) round(sum(is.na(x)) / length(x), 4)
10561056
}
10571057

1058-
qenv <- common_code_q()
1059-
1060-
if (!is.null(group_var)) {
1061-
qenv <- teal.code::eval_code(
1062-
qenv,
1058+
qenv <- if (!is.null(group_var)) {
1059+
teal.code::eval_code(
1060+
common_code_q(),
10631061
substitute(
10641062
expr = {
1065-
table <- ANL %>%
1063+
summary_data <- ANL %>%
10661064
dplyr::mutate(group_var_name := forcats::fct_na_value_to_level(as.factor(group_var_name), "NA")) %>%
10671065
dplyr::group_by_at(group_var) %>%
10681066
dplyr::filter(group_var_name %in% group_vals)
10691067

1070-
count_data <- dplyr::summarise(table, n = dplyr::n())
1068+
count_data <- dplyr::summarise(summary_data, n = dplyr::n())
10711069

1072-
table <- dplyr::summarise_all(table, summ_fn) %>%
1070+
summary_data <- dplyr::summarise_all(summary_data, summ_fn) %>%
10731071
dplyr::mutate(group_var_name := paste0(group_var, ":", group_var_name, "(N=", count_data$n, ")")) %>%
10741072
tidyr::pivot_longer(!dplyr::all_of(group_var), names_to = "Variable", values_to = "out") %>%
10751073
tidyr::pivot_wider(names_from = group_var, values_from = "out") %>%
@@ -1081,8 +1079,8 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
10811079
)
10821080
)
10831081
} else {
1084-
qenv <- teal.code::eval_code(
1085-
qenv,
1082+
teal.code::eval_code(
1083+
common_code_q(),
10861084
substitute(
10871085
expr = summary_data <- ANL %>%
10881086
dplyr::summarise_all(summ_fn) %>%
@@ -1096,7 +1094,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
10961094
)
10971095
}
10981096

1099-
within(qenv, quote(table <- DT::datatable(summary_data)))
1097+
within(qenv, table <- DT::datatable(summary_data))
11001098
})
11011099

11021100
by_subject_plot_q <- reactive({
@@ -1257,19 +1255,24 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
12571255
})
12581256

12591257
# summary_table_q
1260-
decorated_summary_table_q <- srv_transform_teal_data(
1258+
decorated_summary_table_q_no_print <- srv_transform_teal_data(
12611259
id = "decorator",
12621260
data = summary_table_q,
12631261
transformators = decorators
12641262
)
1263+
decorated_summary_table_q <- reactive(
1264+
within(decorated_summary_table_q_no_print(), expr = table)
1265+
)
12651266

12661267
# by_subject_plot_q
12671268
decorated_by_subject_plot_q_no_print <- srv_transform_teal_data(
12681269
id = "decorator",
12691270
data = by_subject_plot_q,
12701271
transformators = decorators
12711272
)
1272-
decorated_by_subject_plot_q <- reactive(within(decorated_by_subject_plot_q_no_print(), print(plot)))
1273+
decorated_by_subject_plot_q <- reactive(
1274+
within(decorated_by_subject_plot_q_no_print(), print(plot))
1275+
)
12731276

12741277
# Output objects for use in widgets
12751278
summary_plot_r <- reactive({
@@ -1297,12 +1300,14 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
12971300
if (length(input$variables_select) == 0) {
12981301
# so that zeroRecords message gets printed
12991302
# using tibble as it supports weird column names, such as " "
1300-
tibble::tibble(` ` = logical(0))
1303+
DT::datatable(
1304+
tibble::tibble(` ` = logical(0)),
1305+
options = list(language = list(zeroRecords = "No variable selected."), pageLength = input$levels_table_rows)
1306+
)
13011307
} else {
13021308
summary_table_r()
13031309
}
1304-
},
1305-
options = list(language = list(zeroRecords = "No variable selected"), pageLength = input$levels_table_rows)
1310+
}
13061311
)
13071312

13081313
pws1 <- teal.widgets::plot_with_settings_srv(
@@ -1326,23 +1331,23 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
13261331
width = plot_width
13271332
)
13281333

1329-
final_q <- reactive({
1334+
decorated_final_q <- reactive({
13301335
req(input$summary_type)
13311336
sum_type <- input$summary_type
13321337
if (sum_type == "Summary") {
1333-
summary_plot_q()
1338+
decorated_summary_plot_q()
13341339
} else if (sum_type == "Combinations") {
1335-
combination_plot_q()
1340+
decorated_combination_plot_q()
13361341
} else if (sum_type == "By Variable Levels") {
1337-
summary_table_q()
1342+
decorated_summary_table_q()
13381343
} else if (sum_type == "Grouped by Subject") {
1339-
by_subject_plot_q()
1344+
decorated_by_subject_plot_q()
13401345
}
13411346
})
13421347

13431348
teal.widgets::verbatim_popup_srv(
13441349
id = "rcode",
1345-
verbatim_content = reactive(teal.code::get_code(req(final_q()))),
1350+
verbatim_content = reactive(teal.code::get_code(req(decorated_final_q()))),
13461351
title = "Show R Code for Missing Data"
13471352
)
13481353

@@ -1378,7 +1383,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
13781383
card$append_text("Comment", "header3")
13791384
card$append_text(comment)
13801385
}
1381-
card$append_src(teal.code::get_code(req(final_q())))
1386+
card$append_src(teal.code::get_code(req(decorated_final_q())))
13821387
card
13831388
}
13841389
teal.reporter::simple_reporter_srv("simple_reporter", reporter = reporter, card_fun = card_fun)

0 commit comments

Comments
 (0)