Skip to content

Commit 4f7edfd

Browse files
committed
Merge branch 'teal_reportable' of https://github.com/insightsengineering/teal.modules.general into teal_reportable
2 parents 575bfb4 + ed29e04 commit 4f7edfd

File tree

9 files changed

+135
-42
lines changed

9 files changed

+135
-42
lines changed

R/tm_a_regression.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,20 +1021,29 @@ srv_a_regression <- function(id,
10211021
width = plot_width
10221022
)
10231023

1024+
decorated_output_dims_q <- reactive({
1025+
dims <- req(pws$dim())
1026+
q <- req(decorated_output_q())
1027+
teal.reporter::teal_card(q) <- modify_last_chunk_outputs_attributes(
1028+
teal.reporter::teal_card(q), list(dev.width = dims[[1]], dev.height = dims[[2]])
1029+
)
1030+
q
1031+
})
1032+
10241033
output$text <- renderText({
10251034
req(iv_r()$is_valid())
10261035
req(iv_out$is_valid())
10271036
paste(utils::capture.output(summary(fitted()))[-1], collapse = "\n")
10281037
})
10291038

10301039
# Render R code.
1031-
source_code_r <- reactive(teal.code::get_code(req(decorated_output_q())))
1040+
source_code_r <- reactive(teal.code::get_code(req(decorated_output_dims_q())))
10321041

10331042
teal.widgets::verbatim_popup_srv(
10341043
id = "rcode",
10351044
verbatim_content = source_code_r,
10361045
title = "R code for the regression plot",
10371046
)
1038-
decorated_output_q
1047+
decorated_output_dims_q
10391048
})
10401049
}

R/tm_g_association.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,25 @@ srv_tm_g_association <- function(id,
542542
width = plot_width
543543
)
544544

545+
decorated_output_dims_q <- reactive({
546+
dims <- req(pws$dim())
547+
q <- req(decorated_output_grob_q())
548+
teal.reporter::teal_card(q) <- modify_last_chunk_outputs_attributes(
549+
teal.reporter::teal_card(q), list(dev.width = dims[[1]], dev.height = dims[[2]])
550+
)
551+
q
552+
})
553+
545554
output$title <- renderText(output_q()[["title"]])
546555

547556
# Render R code.
548-
source_code_r <- reactive(teal.code::get_code(req(decorated_output_grob_q())))
557+
source_code_r <- reactive(teal.code::get_code(req(decorated_output_dims_q())))
549558

550559
teal.widgets::verbatim_popup_srv(
551560
id = "rcode",
552561
verbatim_content = source_code_r,
553562
title = "Association Plot"
554563
)
555-
decorated_output_grob_q
564+
decorated_output_dims_q
556565
})
557566
}

R/tm_g_bivariate.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -741,16 +741,25 @@ srv_g_bivariate <- function(id,
741741
width = plot_width
742742
)
743743

744+
decorated_output_dims_q <- reactive({
745+
dims <- req(pws$dim())
746+
q <- req(decorated_output_q_facets())
747+
teal.reporter::teal_card(q) <- modify_last_chunk_outputs_attributes(
748+
teal.reporter::teal_card(q), list(dev.width = dims[[1]], dev.height = dims[[2]])
749+
)
750+
q
751+
})
752+
744753
# Render R code.
745754

746-
source_code_r <- reactive(teal.code::get_code(req(decorated_output_q_facets())))
755+
source_code_r <- reactive(teal.code::get_code(req(decorated_output_dims_q())))
747756

748757
teal.widgets::verbatim_popup_srv(
749758
id = "rcode",
750759
verbatim_content = source_code_r,
751760
title = "Bivariate Plot"
752761
)
753-
decorated_output_q_facets
762+
decorated_output_dims_q
754763
})
755764
}
756765

R/tm_g_distribution.R

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,20 +1339,7 @@ srv_distribution <- function(id,
13391339
expr = quote(test_table)
13401340
)
13411341

1342-
decorated_output_q <- reactive({
1343-
tab <- req(input$tabs) # tab is NULL upon app launch, hence will crash without this statement
1344-
test_q_out <- try(test_q(), silent = TRUE)
1345-
test_q_out <- output_test_q()
1346-
1347-
out_q <- switch(tab,
1348-
Histogram = decorated_output_dist_q(),
1349-
QQplot = decorated_output_qq_q()
1350-
)
1351-
c(out_q, output_summary_q(), test_q_out)
1352-
})
1353-
13541342
dist_r <- reactive(req(decorated_output_dist_q())[["histogram_plot"]])
1355-
13561343
qq_r <- reactive(req(decorated_output_qq_q())[["qq_plot"]])
13571344

13581345
summary_r <- reactive({
@@ -1398,29 +1385,52 @@ srv_distribution <- function(id,
13981385
brushing = FALSE
13991386
)
14001387

1401-
output$t_stats <- DT::renderDataTable(tests_r()[["html"]])
1388+
decorated_output_dist_dims_q <- reactive({
1389+
dims <- req(pws1$dim())
1390+
q <- req(decorated_output_dist_q())
1391+
teal.reporter::teal_card(q) <- modify_last_chunk_outputs_attributes(
1392+
teal.reporter::teal_card(q), list(dev.width = dims[[1]], dev.height = dims[[2]])
1393+
)
1394+
q
1395+
})
14021396

1403-
# Render R code.
1404-
source_code_r <- reactive(teal.code::get_code(req(decorated_output_q())))
1397+
decorated_output_qq_dims_q <- reactive({
1398+
dims <- req(pws2$dim())
1399+
q <- req(decorated_output_qq_q())
1400+
teal.reporter::teal_card(q) <- modify_last_chunk_outputs_attributes(
1401+
teal.reporter::teal_card(q), list(dev.width = dims[[1]], dev.height = dims[[2]])
1402+
)
1403+
q
1404+
})
14051405

1406-
teal.widgets::verbatim_popup_srv(
1407-
id = "rcode",
1408-
verbatim_content = source_code_r,
1409-
title = "R Code for distribution"
1410-
)
1411-
reactive(
1406+
decorated_output_q <- reactive({
1407+
tab <- req(input$tabs) # tab is NULL upon app launch, hence will crash without this statement
1408+
test_q_out <- output_test_q()
1409+
1410+
out_q <- switch(tab,
1411+
Histogram = decorated_output_dist_dims_q(),
1412+
QQplot = decorated_output_qq_dims_q()
1413+
)
14121414
withCallingHandlers(
1413-
if (input$tabs == "Histogram") {
1414-
c(decorated_output_dist_q(), decorated_output_summary_q(), decorated_output_test_q())
1415-
} else if (input$tabs == "QQplot") {
1416-
c(decorated_output_qq_q(), decorated_output_summary_q(), decorated_output_test_q())
1417-
},
1415+
c(out_q, output_summary_q(), test_q_out),
14181416
warning = function(w) {
14191417
if (grepl("Restoring original content and adding only", conditionMessage(w))) {
14201418
invokeRestart("muffleWarning")
14211419
}
14221420
}
14231421
)
1422+
})
1423+
1424+
output$t_stats <- DT::renderDataTable(tests_r()[["html"]])
1425+
1426+
# Render R code.
1427+
source_code_r <- reactive(teal.code::get_code(req(decorated_output_q())))
1428+
1429+
teal.widgets::verbatim_popup_srv(
1430+
id = "rcode",
1431+
verbatim_content = source_code_r,
1432+
title = "R Code for distribution"
14241433
)
1434+
decorated_output_q
14251435
})
14261436
}

R/tm_g_response.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,23 @@ srv_g_response <- function(id,
594594
width = plot_width
595595
)
596596

597+
decorated_output_dims_q <- reactive({
598+
dims <- req(pws$dim())
599+
q <- req(decorated_output_plot_q())
600+
teal.reporter::teal_card(q) <- modify_last_chunk_outputs_attributes(
601+
teal.reporter::teal_card(q), list(dev.width = dims[[1]], dev.height = dims[[2]])
602+
)
603+
q
604+
})
605+
597606
# Render R code.
598-
source_code_r <- reactive(teal.code::get_code(req(decorated_output_plot_q())))
607+
source_code_r <- reactive(teal.code::get_code(req(decorated_output_dims_q())))
599608

600609
teal.widgets::verbatim_popup_srv(
601610
id = "rcode",
602611
verbatim_content = source_code_r,
603612
title = "Show R Code for Response"
604613
)
605-
decorated_output_plot_q
614+
decorated_output_dims_q
606615
})
607616
}

R/tm_g_scatterplot.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,15 @@ srv_g_scatterplot <- function(id,
10371037
brushing = TRUE
10381038
)
10391039

1040+
decorated_output_dims_q <- reactive({
1041+
dims <- req(pws$dim())
1042+
q <- req(decorated_output_plot_q())
1043+
teal.reporter::teal_card(q) <- modify_last_chunk_outputs_attributes(
1044+
teal.reporter::teal_card(q), list(dev.width = dims[[1]], dev.height = dims[[2]])
1045+
)
1046+
q
1047+
})
1048+
10401049
output$data_table <- DT::renderDataTable({
10411050
plot_brush <- pws$brush()
10421051

@@ -1066,13 +1075,13 @@ srv_g_scatterplot <- function(id,
10661075
})
10671076

10681077
# Render R code.
1069-
source_code_r <- reactive(teal.code::get_code(req(decorated_output_plot_q())))
1078+
source_code_r <- reactive(teal.code::get_code(req(decorated_output_dims_q())))
10701079

10711080
teal.widgets::verbatim_popup_srv(
10721081
id = "rcode",
10731082
verbatim_content = source_code_r,
10741083
title = "R Code for scatterplot"
10751084
)
1076-
decorated_output_plot_q
1085+
decorated_output_dims_q
10771086
})
10781087
}

R/tm_g_scatterplotmatrix.R

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,15 @@ srv_g_scatterplotmatrix <- function(id,
479479
width = plot_width
480480
)
481481

482+
decorated_output_dims_q <- reactive({
483+
dims <- req(pws$dim())
484+
q <- req(decorated_output_q())
485+
teal.reporter::teal_card(q) <- modify_last_chunk_outputs_attributes(
486+
teal.reporter::teal_card(q), list(dev.width = dims[[1]], dev.height = dims[[2]])
487+
)
488+
q
489+
})
490+
482491
# show a message if conversion to factors took place
483492
output$message <- renderText({
484493
req(iv_r()$is_valid())
@@ -502,14 +511,14 @@ srv_g_scatterplotmatrix <- function(id,
502511
})
503512

504513
# Render R code.
505-
source_code_r <- reactive(teal.code::get_code(req(decorated_output_q())))
514+
source_code_r <- reactive(teal.code::get_code(req(decorated_output_dims_q())))
506515

507516
teal.widgets::verbatim_popup_srv(
508517
id = "rcode",
509518
verbatim_content = source_code_r,
510519
title = "Show R Code for Scatterplotmatrix"
511520
)
512-
decorated_output_q
521+
decorated_output_dims_q
513522
})
514523
}
515524

R/tm_missing_data.R

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,16 +1373,43 @@ srv_missing_data <- function(id,
13731373
width = plot_width
13741374
)
13751375

1376+
decorated_summary_plot_dims_q <- reactive({
1377+
dims <- req(pws1$dim())
1378+
q <- req(decorated_summary_plot_q())
1379+
teal.reporter::teal_card(q) <- modify_last_chunk_outputs_attributes(
1380+
teal.reporter::teal_card(q), list(dev.width = dims[[1]], dev.height = dims[[2]])
1381+
)
1382+
q
1383+
})
1384+
1385+
decorated_combination_plot_dims_q <- reactive({
1386+
dims <- req(pws2$dim())
1387+
q <- req(decorated_combination_plot_q())
1388+
teal.reporter::teal_card(q) <- modify_last_chunk_outputs_attributes(
1389+
teal.reporter::teal_card(q), list(dev.width = dims[[1]], dev.height = dims[[2]])
1390+
)
1391+
q
1392+
})
1393+
1394+
decorated_by_subject_plot_dims_q <- reactive({
1395+
dims <- req(pws3$dim())
1396+
q <- req(decorated_by_subject_plot_q())
1397+
teal.reporter::teal_card(q) <- modify_last_chunk_outputs_attributes(
1398+
teal.reporter::teal_card(q), list(dev.width = dims[[1]], dev.height = dims[[2]])
1399+
)
1400+
q
1401+
})
1402+
13761403
decorated_final_q <- reactive({
13771404
sum_type <- req(input$summary_type)
13781405
if (sum_type == "Summary") {
1379-
decorated_summary_plot_q()
1406+
decorated_output_summary_plot_dims_q()
13801407
} else if (sum_type == "Combinations") {
1381-
decorated_combination_plot_q()
1408+
decorated_combination_plot_dims_q()
13821409
} else if (sum_type == "By Variable Levels") {
13831410
decorated_summary_table_q()
13841411
} else if (sum_type == "Grouped by Subject") {
1385-
decorated_by_subject_plot_q()
1412+
decorated_by_subject_plot_dims_q()
13861413
}
13871414
})
13881415

R/tm_outliers.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,8 @@ srv_outliers <- function(id, data, outlier_var,
11701170
brushing = TRUE
11711171
)
11721172

1173+
1174+
11731175
choices <- reactive(teal.transform::variable_choices(data_obj()[[dataname_first]]))
11741176

11751177
observeEvent(common_code_q(), {

0 commit comments

Comments
 (0)