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` (`datatables` created with [DT::datatable()])
35- # ' - `test_table` (`datatables` created with [DT::datatable()])
3634# '
3735# ' A Decorator is applied to the specific output using a named list of `teal_transform_module` objects.
3836# ' The name of this list corresponds to the name of the output to which the decorator is applied.
4341# ' ..., # arguments for module
4442# ' decorators = list(
4543# ' histogram_plot = teal_transform_module(...), # applied only to `histogram_plot` output
46- # ' qq_plot = teal_transform_module(...), # applied only to `qq_plot` output
47- # ' summary_table = teal_transform_module(...), # applied only to `summary_table` output
48- # ' test_table = teal_transform_module(...) # applied only to `test_table` output
44+ # ' qq_plot = teal_transform_module(...) # applied only to `qq_plot` output
4945# ' )
5046# ' )
5147# ' ```
@@ -194,8 +190,7 @@ tm_g_distribution <- function(label = "Distribution Module",
194190 checkmate :: assert_multi_class(pre_output , c(" shiny.tag" , " shiny.tag.list" , " html" ), null.ok = TRUE )
195191 checkmate :: assert_multi_class(post_output , c(" shiny.tag" , " shiny.tag.list" , " html" ), null.ok = TRUE )
196192
197- available_decorators <- c(" histogram_plot" , " qq_plot" , " test_table" , " summary_table" )
198- assert_decorators(decorators , names = available_decorators )
193+ assert_decorators(decorators , names = c(" histogram_plot" , " qq_plot" ))
199194
200195 # End of assertions
201196
@@ -322,14 +317,6 @@ ui_distribution <- function(id, ...) {
322317 collapsed = FALSE
323318 )
324319 ),
325- ui_decorate_teal_data(
326- ns(" d_summary" ),
327- decorators = select_decorators(args $ decorators , " summary_table" )
328- ),
329- ui_decorate_teal_data(
330- ns(" d_test" ),
331- decorators = select_decorators(args $ decorators , " test_table" )
332- ),
333320 conditionalPanel(
334321 condition = paste0(" input['" , ns(" main_type" ), " '] == 'Density'" ),
335322 bslib :: accordion_panel(
@@ -1284,24 +1271,31 @@ srv_distribution <- function(id,
12841271 # Summary table listing has to be created separately to allow for qenv join
12851272 output_summary_q <- reactive({
12861273 if (iv_r()$ is_valid()) {
1287- within(common_q(), summary_table <- DT :: datatable(summary_table_data ))
1274+ within(common_q(), {
1275+ summary_table <- rtables :: df_to_tt(summary_table_data )
1276+ summary_table
1277+ })
12881278 } else {
1289- within(common_q(), summary_table <- DT :: datatable(summary_table_data [0L , ]))
1279+ within(
1280+ common_q(),
1281+ summary_table <- rtables :: rtable(header = rtables :: rheader(colnames(summary_table_data )))
1282+ )
12901283 }
12911284 })
12921285
12931286 output_test_q <- reactive({
12941287 # wrapped in if since could lead into validate error - we do want to continue
12951288 test_q_out <- try(test_q(), silent = TRUE )
1296- if (! inherits(test_q_out , c(" try-error" , " error" ))) {
1297- c (
1289+ if (inherits(test_q_out , c(" try-error" , " error" ))) {
1290+ within (
12981291 common_q(),
1299- within(test_q_out , {
1300- test_table <- DT :: datatable(test_table_data )
1301- })
1292+ test_table <- rtables :: rtable(header = rtables :: rheader(" No data available in table" ), rtables :: rrow())
13021293 )
13031294 } else {
1304- within(common_q(), test_table <- DT :: datatable(data.frame (missing = character (0L ))))
1295+ within(c(common_q(), test_q_out ), {
1296+ test_table <- rtables :: df_to_tt(test_table_data )
1297+ test_table
1298+ })
13051299 }
13061300 })
13071301
@@ -1319,54 +1313,47 @@ srv_distribution <- function(id,
13191313 expr = print(qq_plot )
13201314 )
13211315
1322- decorated_output_summary_q <- srv_decorate_teal_data(
1323- " d_summary" ,
1324- data = output_summary_q ,
1325- decorators = select_decorators(decorators , " summary_table" ),
1326- expr = summary_table
1327- )
1328-
1329- decorated_output_test_q <- srv_decorate_teal_data(
1330- " d_test" ,
1331- data = output_test_q ,
1332- decorators = select_decorators(decorators , " test_table" ),
1333- expr = test_table
1334- )
1335-
13361316 decorated_output_q <- reactive({
13371317 tab <- req(input $ tabs ) # tab is NULL upon app launch, hence will crash without this statement
13381318 test_q_out <- try(test_q(), silent = TRUE )
1339- decorated_test_q_out <- if (inherits(test_q_out , c(" try-error" , " error" ))) {
1340- teal.code :: qenv()
1341- } else {
1342- decorated_output_test_q()
1343- }
1319+ test_q_out <- output_test_q()
13441320
13451321 out_q <- switch (tab ,
13461322 Histogram = decorated_output_dist_q(),
13471323 QQplot = decorated_output_qq_q()
13481324 )
1349- c(out_q , decorated_output_summary_q (), decorated_test_q_out )
1325+ c(out_q , output_summary_q (), test_q_out )
13501326 })
13511327
13521328 dist_r <- reactive(req(decorated_output_dist_q())[[" histogram_plot" ]])
13531329
13541330 qq_r <- reactive(req(decorated_output_qq_q())[[" qq_plot" ]])
13551331
1356- output $ summary_table <- DT :: renderDataTable(
1357- expr = decorated_output_summary_q()[[" summary_table" ]],
1358- options = list (
1359- autoWidth = TRUE ,
1360- columnDefs = list (list (width = " 200px" , targets = " _all" ))
1361- ),
1362- rownames = FALSE
1363- )
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" ]])
13641349
13651350 tests_r <- reactive({
1366- req(iv_r()$ is_valid())
1367- teal :: validate_inputs(iv_r_dist())
1368- req(test_q()) # Ensure original errors are displayed
1369- decorated_output_test_q()[[" test_table" ]]
1351+ q <- req(output_test_q())
1352+
1353+ list (
1354+ html = DT :: datatable(q [[" test_table_data" ]]),
1355+ report = q [[" test_table" ]]
1356+ )
13701357 })
13711358
13721359 pws1 <- teal.widgets :: plot_with_settings_srv(
@@ -1385,7 +1372,7 @@ srv_distribution <- function(id,
13851372 brushing = FALSE
13861373 )
13871374
1388- output $ t_stats <- DT :: renderDataTable(expr = tests_r())
1375+ output $ t_stats <- DT :: renderDataTable(tests_r()[[ " html " ]] )
13891376
13901377 # Render R code.
13911378 source_code_r <- reactive(teal.code :: get_code(req(decorated_output_q())))
@@ -1412,11 +1399,11 @@ srv_distribution <- function(id,
14121399 card $ append_plot(qq_r(), dim = pws2 $ dim())
14131400 }
14141401 card $ append_text(" Statistics table" , " header3" )
1415- card $ append_table(decorated_output_summary_q ()[[" summary_table " ]])
1402+ card $ append_table(summary_r ()[[" report " ]])
14161403 tests_error <- tryCatch(expr = tests_r(), error = function (e ) " error" )
1417- if (inherits (tests_error , " data.frame " )) {
1404+ if (! identical (tests_error , " error " )) {
14181405 card $ append_text(" Tests table" , " header3" )
1419- card $ append_table(tests_r())
1406+ card $ append_table(tests_r()[[ " report " ]] )
14201407 }
14211408
14221409 if (! comment == " " ) {
0 commit comments