@@ -859,40 +859,6 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
859859 qenv
860860 })
861861
862-
863- decorated_summary_plot_q <- srv_transform_teal_data(id = " decorator" , data = summary_plot_q , transformators = decorators )
864- decorated_summary_plot_grob_q <- reactive({
865- q <- if (isTRUE(input $ if_patients_plot )) {
866- within(
867- decorated_summary_plot_q(),
868- {
869- g1 <- ggplotGrob(summary_plot_top )
870- g2 <- ggplotGrob(summary_plot_bottom )
871- g <- gridExtra :: gtable_cbind(g1 , g2 , size = " first" )
872- g $ heights <- grid :: unit.pmax(g1 $ heights , g2 $ heights )
873- grid :: grid.newpage()
874- }
875- )
876- } else {
877- within(
878- decorated_summary_plot_q(),
879- {
880- g <- ggplotGrob(summary_plot_top )
881- grid :: grid.newpage()
882- }
883- )
884- }
885- teal.code :: eval_code(
886- q ,
887- quote(grid :: grid.draw(g ))
888- )
889- })
890-
891- summary_plot_r <- reactive({
892- req(summary_plot_q())
893- decorated_summary_plot_grob_q()[[" g" ]]
894- })
895-
896862 combination_cutoff_q <- reactive({
897863 req(common_code_q())
898864 teal.code :: eval_code(
@@ -1053,27 +1019,6 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
10531019 )
10541020 })
10551021
1056- decorated_combination_plot_q <- srv_transform_teal_data(id = " decorator" , data = combination_plot_q , transformators = decorators )
1057- decorated_combination_plot_grob_q <- reactive({
1058- within(
1059- decorated_combination_plot_q(),
1060- {
1061- g1 <- ggplotGrob(combination_plot_top )
1062- g2 <- ggplotGrob(combination_plot_bottom )
1063-
1064- g <- gridExtra :: gtable_rbind(g1 , g2 , size = " last" )
1065- g $ heights [7 ] <- grid :: unit(0.2 , " null" ) # rescale to get the bar chart smaller
1066- grid :: grid.newpage()
1067- grid :: grid.draw(g )
1068- }
1069- )
1070- })
1071-
1072- combination_plot_r <- reactive({
1073- req(combination_plot_q())
1074- decorated_combination_plot_grob_q()[[" g" ]]
1075- })
1076-
10771022 summary_table_q <- reactive({
10781023 req(
10791024 input $ summary_type == " By Variable Levels" , # needed to trigger show r code update on tab change
@@ -1117,14 +1062,14 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
11171062 qenv ,
11181063 substitute(
11191064 expr = {
1120- summary_data <- ANL %> %
1065+ table <- ANL %> %
11211066 dplyr :: mutate(group_var_name : = forcats :: fct_na_value_to_level(as.factor(group_var_name ), " NA" )) %> %
11221067 dplyr :: group_by_at(group_var ) %> %
11231068 dplyr :: filter(group_var_name %in% group_vals )
11241069
1125- count_data <- dplyr :: summarise(summary_data , n = dplyr :: n())
1070+ count_data <- dplyr :: summarise(table , n = dplyr :: n())
11261071
1127- summary_data <- dplyr :: summarise_all(summary_data , summ_fn ) %> %
1072+ table <- dplyr :: summarise_all(table , summ_fn ) %> %
11281073 dplyr :: mutate(group_var_name : = paste0(group_var , " :" , group_var_name , " (N=" , count_data $ n , " )" )) %> %
11291074 tidyr :: pivot_longer(! dplyr :: all_of(group_var ), names_to = " Variable" , values_to = " out" ) %> %
11301075 tidyr :: pivot_wider(names_from = group_var , values_from = " out" ) %> %
@@ -1151,14 +1096,7 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
11511096 )
11521097 }
11531098
1154- teal.code :: eval_code(qenv , quote(table <- DT :: datatable(summary_data )))
1155- })
1156-
1157- decorated_summary_table_q <-
1158- srv_transform_teal_data(id = " decorator" , data = summary_table_q , transformators = decorators )
1159- summary_table_r <- reactive({
1160- req(summary_table_q())
1161- decorated_summary_table_q()[[" table" ]]
1099+ within(qenv , quote(table <- DT :: datatable(summary_data )))
11621100 })
11631101
11641102 by_subject_plot_q <- reactive({
@@ -1267,12 +1205,92 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
12671205 )
12681206 })
12691207
1270- decorated_by_subject_plot_q <- srv_transform_teal_data(id = " decorator" , data = by_subject_plot_q , transformators = decorators )
1271- decorated_by_subject_plot_print_q <- reactive(within(decorated_by_subject_plot_q(), print(plot )))
1208+ # Start decoration of objects
1209+
1210+ # summary_plot_q
1211+ decorated_summary_plot_q_no_print <- srv_transform_teal_data(
1212+ id = " decorator" ,
1213+ data = summary_plot_q ,
1214+ transformators = decorators
1215+ )
1216+ decorated_summary_plot_q <- reactive({
1217+ expr <- if (isTRUE(input $ if_patients_plot )) {
1218+ quote({
1219+ g1 <- ggplotGrob(summary_plot_top )
1220+ g2 <- ggplotGrob(summary_plot_bottom )
1221+ plot <- gridExtra :: gtable_cbind(g1 , g2 , size = " first" )
1222+ plot $ heights <- grid :: unit.pmax(g1 $ heights , g2 $ heights )
1223+ })
1224+ } else {
1225+ quote({
1226+ g1 <- ggplotGrob(summary_plot_top )
1227+ plot <- g1
1228+ })
1229+ }
1230+ # browser()
1231+ decorated_summary_plot_q_no_print() %> %
1232+ eval_code(expr ) %> %
1233+ within({
1234+ grid :: grid.newpage()
1235+ grid :: grid.draw(plot )
1236+ })
1237+ })
1238+
1239+ # combination_plot_q
1240+ decorated_combination_plot_q_no_print <- srv_transform_teal_data(
1241+ id = " decorator" ,
1242+ data = combination_plot_q ,
1243+ transformators = decorators
1244+ )
1245+ decorated_combination_plot_q <- reactive({
1246+ within(
1247+ decorated_combination_plot_q_no_print(),
1248+ {
1249+ g1 <- ggplotGrob(combination_plot_top )
1250+ g2 <- ggplotGrob(combination_plot_bottom )
1251+
1252+ plot <- gridExtra :: gtable_rbind(g1 , g2 , size = " last" )
1253+ plot $ heights [7 ] <- grid :: unit(0.2 , " null" ) # rescale to get the bar chart smaller
1254+ grid :: grid.newpage()
1255+ grid :: grid.draw(plot )
1256+ }
1257+ )
1258+ })
1259+
1260+ # summary_table_q
1261+ decorated_summary_table_q <- srv_transform_teal_data(
1262+ id = " decorator" ,
1263+ data = summary_table_q ,
1264+ transformators = decorators
1265+ )
1266+
1267+ # by_subject_plot_q
1268+ decorated_by_subject_plot_q_no_print <- srv_transform_teal_data(
1269+ id = " decorator" ,
1270+ data = by_subject_plot_q ,
1271+ transformators = decorators
1272+ )
1273+ decorated_by_subject_plot_q <- reactive(within(decorated_by_subject_plot_q_no_print(), print(plot )))
1274+
1275+ # Output objects for use in widgets
1276+ summary_plot_r <- reactive({
1277+ req(summary_plot_q())
1278+ decorated_summary_plot_q()[[" plot" ]]
1279+ })
1280+
1281+ combination_plot_r <- reactive({
1282+ req(combination_plot_q())
1283+ decorated_combination_plot_q()[[" plot" ]]
1284+ })
1285+
1286+ summary_table_r <- reactive({
1287+ req(summary_table_q())
1288+ decorated_summary_table_q()[[" table" ]]
1289+ })
12721290
12731291 by_subject_plot_r <- reactive({
12741292 req(by_subject_plot_q()) # Ensure original errors are displayed
1275- decorated_by_subject_plot_print_q ()[[" plot" ]]
1293+ decorated_by_subject_plot_q ()[[" plot" ]]
12761294 })
12771295
12781296 output $ levels_table <- DT :: renderDataTable(
0 commit comments