3131# ' This module generates the following objects, which can be modified in place using decorators::
3232# ' - `histogram_plot` (`ggplot`)
3333# ' - `qq_plot` (`ggplot`)
34- # ' - `summary_table` (`ElementaryTable` created with [rtables::df_to_tt()])
35- # ' - The decorated table is only shown in the reporter as it is presented as an interactive `DataTable` in the module.
36- # ' - `test_table` (`ElementaryTable` created with [rtables::df_to_tt()])
37- # ' - The decorated table is only shown in the reporter as it is presented as an interactive `DataTable` in the module.
3834# '
3935# ' A Decorator is applied to the specific output using a named list of `teal_transform_module` objects.
4036# ' The name of this list corresponds to the name of the output to which the decorator is applied.
4541# ' ..., # arguments for module
4642# ' decorators = list(
4743# ' histogram_plot = teal_transform_module(...), # applied only to `histogram_plot` output
48- # ' qq_plot = teal_transform_module(...), # applied only to `qq_plot` output
49- # ' summary_table = teal_transform_module(...), # applied only to `summary_table` output
50- # ' test_table = teal_transform_module(...) # applied only to `test_table` output
44+ # ' qq_plot = teal_transform_module(...) # applied only to `qq_plot` output
5145# ' )
5246# ' )
5347# ' ```
@@ -196,8 +190,7 @@ tm_g_distribution <- function(label = "Distribution Module",
196190 checkmate :: assert_multi_class(pre_output , c(" shiny.tag" , " shiny.tag.list" , " html" ), null.ok = TRUE )
197191 checkmate :: assert_multi_class(post_output , c(" shiny.tag" , " shiny.tag.list" , " html" ), null.ok = TRUE )
198192
199- available_decorators <- c(" histogram_plot" , " qq_plot" , " test_table" , " summary_table" )
200- assert_decorators(decorators , names = available_decorators )
193+ assert_decorators(decorators , names = c(" histogram_plot" , " qq_plot" ))
201194
202195 # End of assertions
203196
@@ -324,14 +317,6 @@ ui_distribution <- function(id, ...) {
324317 collapsed = FALSE
325318 )
326319 ),
327- ui_decorate_teal_data(
328- ns(" d_summary" ),
329- decorators = select_decorators(args $ decorators , " summary_table" )
330- ),
331- ui_decorate_teal_data(
332- ns(" d_test" ),
333- decorators = select_decorators(args $ decorators , " test_table" )
334- ),
335320 conditionalPanel(
336321 condition = paste0(" input['" , ns(" main_type" ), " '] == 'Density'" ),
337322 bslib :: accordion_panel(
@@ -1286,14 +1271,17 @@ srv_distribution <- function(id,
12861271 # Summary table listing has to be created separately to allow for qenv join
12871272 output_summary_q <- reactive({
12881273 if (iv_r()$ is_valid()) {
1289- within(common_q(), summary_table <- rtables :: df_to_tt(summary_table_data ))
1274+ within(common_q(), {
1275+ summary_table <- rtables :: df_to_tt(summary_table_data )
1276+ summary_table
1277+ })
12901278 } else {
12911279 within(
12921280 common_q(),
12931281 summary_table <- rtables :: rtable(header = rtables :: rheader(colnames(summary_table_data )))
12941282 )
12951283 }
1296- })
1284+ })
12971285
12981286 output_test_q <- reactive({
12991287 # wrapped in if since could lead into validate error - we do want to continue
@@ -1304,7 +1292,10 @@ srv_distribution <- function(id,
13041292 test_table <- rtables :: rtable(header = rtables :: rheader(" No data available in table" ), rtables :: rrow())
13051293 )
13061294 } else {
1307- within(c(common_q(), test_q_out ), test_table <- rtables :: df_to_tt(test_table_data ))
1295+ within(c(common_q(), test_q_out ), {
1296+ test_table <- rtables :: df_to_tt(test_table_data )
1297+ test_table
1298+ })
13081299 }
13091300 })
13101301
@@ -1322,47 +1313,42 @@ srv_distribution <- function(id,
13221313 expr = print(qq_plot )
13231314 )
13241315
1325- decorated_output_summary_q <- srv_decorate_teal_data(
1326- " d_summary" ,
1327- data = output_summary_q ,
1328- decorators = select_decorators(decorators , " summary_table" ),
1329- expr = summary_table
1330- )
1331-
1332- decorated_output_test_q <- srv_decorate_teal_data(
1333- " d_test" ,
1334- data = output_test_q ,
1335- decorators = select_decorators(decorators , " test_table" ),
1336- expr = test_table
1337- )
1338-
13391316 decorated_output_q <- reactive({
13401317 tab <- req(input $ tabs ) # tab is NULL upon app launch, hence will crash without this statement
13411318 test_q_out <- try(test_q(), silent = TRUE )
1342- decorated_test_q_out <- decorated_output_test_q ()
1319+ test_q_out <- output_test_q ()
13431320
13441321 out_q <- switch (tab ,
13451322 Histogram = decorated_output_dist_q(),
13461323 QQplot = decorated_output_qq_q()
13471324 )
1348- c(out_q , decorated_output_summary_q (), decorated_test_q_out )
1325+ c(out_q , output_summary_q (), test_q_out )
13491326 })
13501327
13511328 dist_r <- reactive(req(decorated_output_dist_q())[[" histogram_plot" ]])
13521329
13531330 qq_r <- reactive(req(decorated_output_qq_q())[[" qq_plot" ]])
13541331
1355- output $ summary_table <- DT :: renderDataTable(
1356- expr = decorated_output_summary_q()[[" summary_table_data" ]],
1357- options = list (
1358- autoWidth = TRUE ,
1359- columnDefs = list (list (width = " 200px" , targets = " _all" ))
1360- ),
1361- rownames = FALSE
1362- )
1332+ summary_r <- reactive({
1333+ q <- req(output_summary_q())
1334+
1335+ list (
1336+ html = DT :: datatable(
1337+ q [[" summary_table_data" ]],
1338+ options = list (
1339+ autoWidth = TRUE ,
1340+ columnDefs = list (list (width = " 200px" , targets = " _all" ))
1341+ ),
1342+ rownames = FALSE
1343+ ),
1344+ report = q [[" summary_table" ]]
1345+ )
1346+ })
1347+
1348+ output $ summary_table <- DT :: renderDataTable(summary_r()[[" html" ]])
13631349
13641350 tests_r <- reactive({
1365- q <- req(decorated_output_test_q ())
1351+ q <- req(output_test_q ())
13661352
13671353 list (
13681354 html = DT :: datatable(q [[" test_table_data" ]]),
@@ -1386,7 +1372,7 @@ srv_distribution <- function(id,
13861372 brushing = FALSE
13871373 )
13881374
1389- output $ t_stats <- DT :: renderDataTable(expr = tests_r()[[" html" ]])
1375+ output $ t_stats <- DT :: renderDataTable(tests_r()[[" html" ]])
13901376
13911377 # Render R code.
13921378 source_code_r <- reactive(teal.code :: get_code(req(decorated_output_q())))
@@ -1413,7 +1399,7 @@ srv_distribution <- function(id,
14131399 card $ append_plot(qq_r(), dim = pws2 $ dim())
14141400 }
14151401 card $ append_text(" Statistics table" , " header3" )
1416- card $ append_table(decorated_output_summary_q ()[[" summary_table " ]])
1402+ card $ append_table(summary_r ()[[" report " ]])
14171403 tests_error <- tryCatch(expr = tests_r(), error = function (e ) " error" )
14181404 if (! identical(tests_error , " error" )) {
14191405 card $ append_text(" Tests table" , " header3" )
0 commit comments