3030# '
3131# ' This module generates the following objects, which can be modified in place using decorators::
3232# ' - `histogram_plot` (`ggplot2`)
33- # ' - `qq_plot` (`data.frame `)
34- # ' - `summary_table` (`data.frame` )
35- # ' - `test_table` (`data.frame` )
33+ # ' - `qq_plot` (`ggplot2 `)
34+ # ' - `summary_table` (`listing_df` created with [rlistings::as_listing()] )
35+ # ' - `test_table` (`listing_df` created with [rlistings::as_listing()] )
3636# '
3737# ' Decorators can be applied to all outputs or only to specific objects using a
3838# ' named list of `teal_transform_module` objects.
@@ -712,7 +712,7 @@ srv_distribution <- function(id,
712712 )
713713 }
714714
715- qenv <- if (length(s_var ) == 0 && length(g_var ) == 0 ) {
715+ if (length(s_var ) == 0 && length(g_var ) == 0 ) {
716716 teal.code :: eval_code(
717717 qenv ,
718718 substitute(
@@ -758,20 +758,6 @@ srv_distribution <- function(id,
758758 )
759759 )
760760 }
761- if (iv_r()$ is_valid()) {
762- within(qenv , {
763- summary_table <- DT :: datatable(
764- summary_table_data ,
765- options = list (
766- autoWidth = TRUE ,
767- columnDefs = list (list (width = " 200px" , targets = " _all" ))
768- ),
769- rownames = FALSE
770- )
771- })
772- } else {
773- within(qenv , summary_table <- NULL )
774- }
775761 })
776762
777763 # distplot qenv ----
@@ -1267,29 +1253,33 @@ srv_distribution <- function(id,
12671253 )
12681254
12691255 # outputs ----
1270- # # building main qenv
1271- output_common_q <- reactive({
1256+ output_dist_q <- reactive(c(common_q(), req(dist_q())))
1257+ output_qq_q <- reactive(c(common_q(), req(qq_q())))
1258+
1259+ # Summary table listing has to be created separately to allow for qenv join
1260+ output_summary_q <- reactive({
1261+ if (iv_r()$ is_valid()) {
1262+ within(common_q(), summary_table <- rlistings :: as_listing(summary_table_data ))
1263+ } else {
1264+ within(common_q(), summary_table <- rlistings :: as_listing(summary_table_data [0L , ]))
1265+ }
1266+ })
1267+
1268+ output_test_q <- reactive({
12721269 # wrapped in if since could lead into validate error - we do want to continue
12731270 test_q_out <- try(test_q(), silent = TRUE )
12741271 if (! inherits(test_q_out , c(" try-error" , " error" ))) {
12751272 c(
12761273 common_q(),
12771274 within(test_q_out , {
1278- test_table <- DT :: datatable(
1279- test_table_data ,
1280- options = list (scrollX = TRUE ),
1281- rownames = FALSE
1282- )
1275+ test_table <- rlistings :: as_listing(test_table_data )
12831276 })
12841277 )
12851278 } else {
1286- within(common_q(), test_table <- NULL )
1279+ within(common_q(), test_table <- rlistings :: as_listing( data.frame ( missing = character ( 0L ))) )
12871280 }
12881281 })
12891282
1290- output_dist_q <- reactive(c(output_common_q(), req(dist_q())))
1291- output_qq_q <- reactive(c(output_common_q(), req(qq_q())))
1292-
12931283 decorated_output_dist_q <- srv_decorate_teal_data(
12941284 " d_density" ,
12951285 data = output_dist_q ,
@@ -1306,14 +1296,14 @@ srv_distribution <- function(id,
13061296
13071297 decorated_output_summary_q <- srv_decorate_teal_data(
13081298 " d_summary" ,
1309- data = output_common_q ,
1299+ data = output_summary_q ,
13101300 decorators = select_decorators(decorators , " summary_table" ),
13111301 expr = summary_table
13121302 )
13131303
13141304 decorated_output_test_q <- srv_decorate_teal_data(
13151305 " d_test" ,
1316- data = output_common_q ,
1306+ data = output_test_q ,
13171307 decorators = select_decorators(decorators , " test_table" ),
13181308 expr = test_table
13191309 )
@@ -1338,13 +1328,24 @@ srv_distribution <- function(id,
13381328
13391329 qq_r <- reactive(req(decorated_output_qq_q())[[" qq_plot" ]])
13401330
1341- output $ summary_table <- DT :: renderDataTable(expr = decorated_output_summary_q()[[" summary_table" ]])
1331+ output $ summary_table <- DT :: renderDataTable(
1332+ expr = decorated_output_summary_q()[[" summary_table_data" ]],
1333+ options = list (
1334+ autoWidth = TRUE ,
1335+ columnDefs = list (list (width = " 200px" , targets = " _all" ))
1336+ ),
1337+ rownames = FALSE
1338+ )
13421339
13431340 tests_r <- reactive({
13441341 req(iv_r()$ is_valid())
13451342 teal :: validate_inputs(iv_r_dist())
13461343 req(test_q()) # Ensure original errors are displayed
1347- decorated_output_test_q()[[" test_table" ]]
1344+ DT :: datatable(
1345+ data = decorated_output_test_q()[[" test_table_data" ]],
1346+ options = list (scrollX = TRUE ),
1347+ rownames = FALSE
1348+ )
13481349 })
13491350
13501351 pws1 <- teal.widgets :: plot_with_settings_srv(
@@ -1363,9 +1364,7 @@ srv_distribution <- function(id,
13631364 brushing = FALSE
13641365 )
13651366
1366- output $ t_stats <- DT :: renderDataTable(
1367- expr = tests_r()
1368- )
1367+ output $ t_stats <- DT :: renderDataTable(expr = tests_r())
13691368
13701369 # Render R code.
13711370 source_code_r <- reactive(teal.code :: get_code(req(decorated_output_q())))
@@ -1392,8 +1391,7 @@ srv_distribution <- function(id,
13921391 card $ append_plot(qq_r(), dim = pws2 $ dim())
13931392 }
13941393 card $ append_text(" Statistics table" , " header3" )
1395-
1396- card $ append_table(common_q()[[" summary_table" ]])
1394+ card $ append_table(decorated_output_summary_q()[[" summary_table" ]])
13971395 tests_error <- tryCatch(expr = tests_r(), error = function (e ) " error" )
13981396 if (inherits(tests_error , " data.frame" )) {
13991397 card $ append_text(" Tests table" , " header3" )
0 commit comments