@@ -125,40 +125,12 @@ edish_UI <- function(module_id) {
125125# ' @param dataset_list `[shiny::reactive(list(data.frame))]`
126126# '
127127# ' A reactive list of named datasets.
128- # ' @param subjectid_var `[character(1)]`
129- # '
130- # ' Name of the variable containing the unique subject IDs.
131- # ' @param arm_var `[character(1)]`
132- # '
133- # ' Name of the variable containing the arm/treatment information.
134- # ' @param arm_default_vals `[character(1+)]`
135- # '
136- # ' Vector specifying the default value(s) for the arm selector.
137- # ' @param visit_var `[character(1)]`
138- # '
139- # ' Name of the variable containing the visit information.
140- # ' @param baseline_visit_val `[character(1)]`
141- # '
142- # ' Character indicating which visit should be used as baseline visit.
143- # ' @param lb_test_var `[character(1)]`
144- # '
145- # ' Name of the variable containing the laboratory test information.
146- # ' @param lb_test_choices `[character(1+)]`
147- # '
148- # ' Character vector specifying the possible choices of the laboratory test.
149- # ' @param lb_test_default_x_val `[character(1)]`
150- # '
151- # ' Character specifying the default laboratory test choice for the plot's x-axis.
152- # ' @param lb_test_default_y_val `[character(1)]`
153- # '
154- # ' Character specifying the default laboratory test choice for the plot's y-axis.
155- # ' @param lb_result_var `[character(1)]`
156- # '
157- # ' Name of the variable containing results of the laboratory test.
158- # ' @param ref_range_upper_lim_var `[character(1)]`
159- # '
160- # ' Name of the variable containing the reference range upper limits.
128+ # ' @param afmm_param `[list]`
161129# '
130+ # ' Named list of a selection of arguments from module manager. Expects
131+ # ' at least two elements: \code{utils} and \code{module_names} defining a character vector
132+ # ' whose entries have the corresponding module IDs as names.
133+ # ' @inheritParams mod_edish
162134# ' @seealso [mod_edish()] and [edish_UI()]
163135# ' @export
164136edish_server <- function (
@@ -179,7 +151,10 @@ edish_server <- function(
179151 lb_test_default_x_val = " Aspartate Aminotransferase" ,
180152 lb_test_default_y_val = " Bilirubin" ,
181153 lb_result_var = " LBSTRESN" ,
182- ref_range_upper_lim_var = " LBSTNRHI" ) {
154+ ref_range_upper_lim_var = " LBSTNRHI" ,
155+ receiver_id = NULL ,
156+ afmm_param = NULL ) {
157+
183158 # Check validity of arguments
184159 ac <- checkmate :: makeAssertCollection()
185160 checkmate :: assert_multi_class(dataset_list , c(" reactive" , " shinymeta_reactive" ), add = ac )
@@ -211,11 +186,14 @@ edish_server <- function(
211186 checkmate :: assert_string(lb_test_default_y_val , min.chars = 1 , add = ac )
212187 checkmate :: assert_string(lb_result_var , min.chars = 1 , add = ac )
213188 checkmate :: assert_string(ref_range_upper_lim_var , min.chars = 1 , add = ac )
189+ checkmate :: assert_string(receiver_id , min.chars = 1 , null.ok = TRUE , add = ac )
190+ checkmate :: assert_list(afmm_param , null.ok = TRUE , add = ac )
214191 checkmate :: reportAssertions(ac )
215192
216193
217194 # Initiate module server
218195 shiny :: moduleServer(module_id , function (input , output , session ) {
196+
219197 # Dataset validation
220198 v_dataset_list <- shiny :: reactive({
221199 checkmate :: assert_list(dataset_list(), types = " data.frame" , null.ok = TRUE , names = " named" )
@@ -283,7 +261,7 @@ edish_server <- function(
283261 sel_y = shiny :: req(input [[EDISH $ Y_AXIS_ID ]])
284262 )
285263 })
286-
264+
287265 output [[EDISH $ PLOT_ID ]] <- plotly :: renderPlotly(
288266 generate_plot(
289267 dataset = plot_data(),
@@ -293,7 +271,8 @@ edish_server <- function(
293271 y_plot_type = input [[EDISH $ Y_PLOT_TYPE_ID ]],
294272 x_ref_line_num = input [[EDISH $ X_REF_ID ]], y_ref_line_num = input [[EDISH $ Y_REF_ID ]],
295273 x_rng_lower = input [[EDISH $ X_RNG_ID ]][1 ], x_rng_upper = input [[EDISH $ X_RNG_ID ]][2 ],
296- y_rng_lower = input [[EDISH $ Y_RNG_ID ]][1 ], y_rng_upper = input [[EDISH $ Y_RNG_ID ]][2 ]
274+ y_rng_lower = input [[EDISH $ Y_RNG_ID ]][1 ], y_rng_upper = input [[EDISH $ Y_RNG_ID ]][2 ],
275+ source = " plot"
297276 )
298277 )
299278
@@ -302,6 +281,24 @@ edish_server <- function(
302281 shiny :: validate(shiny :: need(! is.null(plot_data()), " No data available." ))
303282 }
304283 })
284+
285+ # Jumping feature
286+ shiny :: observeEvent(plotly :: event_data(" plotly_click" , source = " plot" ), {
287+ if (! receiver_id %in% names(afmm_param $ module_names ) && ! is.null(receiver_id )) {
288+ shiny :: showNotification(
289+ paste0(" Can't find receiver module with ID " , receiver_id , " ." ),
290+ type = " message"
291+ )
292+ } else if (! is.null(receiver_id )) {
293+ afmm_param $ utils $ switch2mod(receiver_id )
294+ }
295+ })
296+
297+ # Return subj_id for communication with dv.papo
298+ return (
299+ list (subj_id = shiny :: reactive({plotly :: event_data(" plotly_click" , source = " plot" )$ key }))
300+ )
301+
305302 })
306303}
307304
@@ -356,6 +353,10 @@ edish_server <- function(
356353# '
357354# ' Name of the variable containing the reference range upper limits.
358355# ' Defaults to `"LBSTNRHI"`.
356+ # ' @param receiver_id `[character(1) | NULL]`
357+ # '
358+ # ' Character string defining the ID of the module to which to send a subject ID. The
359+ # ' module must exist in the module list. The default is NULL which disables communication.
359360# '
360361# ' @return A list containing the following elements to be used by the
361362# ' \pkg{dv.manager}:
@@ -385,7 +386,8 @@ mod_edish <- function(
385386 lb_test_default_x_val = " Aspartate Aminotransferase" ,
386387 lb_test_default_y_val = " Bilirubin" ,
387388 lb_result_var = " LBSTRESN" ,
388- ref_range_upper_lim_var = " LBSTNRHI" ) {
389+ ref_range_upper_lim_var = " LBSTNRHI" ,
390+ receiver_id = NULL ) {
389391
390392 mod <- list (
391393 ui = function (module_id ) {
@@ -409,7 +411,9 @@ mod_edish <- function(
409411 lb_test_default_x_val = lb_test_default_x_val ,
410412 lb_test_default_y_val = lb_test_default_y_val ,
411413 lb_result_var = lb_result_var ,
412- ref_range_upper_lim_var = ref_range_upper_lim_var
414+ ref_range_upper_lim_var = ref_range_upper_lim_var ,
415+ receiver_id = receiver_id ,
416+ afmm_param = list (utils = afmm $ utils , module_names = afmm $ module_names )
413417 )
414418 },
415419 module_id = module_id
@@ -435,7 +439,8 @@ mod_edish_API_docs <- list(
435439 lb_test_default_x_val = list (" " ),
436440 lb_test_default_y_val = list (" " ),
437441 lb_result_var = list (" " ),
438- ref_range_upper_lim_var = list (" " )
442+ ref_range_upper_lim_var = list (" " ),
443+ receiver_id = list (" " )
439444)
440445
441446mod_edish_API_spec <- TC $ group(
@@ -452,13 +457,14 @@ mod_edish_API_spec <- TC$group(
452457 lb_test_default_x_val = TC $ choice_from_col_contents(" lb_test_var" ) | > TC $ flag(" optional" ),
453458 lb_test_default_y_val = TC $ choice_from_col_contents(" lb_test_var" ) | > TC $ flag(" optional" ),
454459 lb_result_var = TC $ col(" lab_dataset_name" , TC $ or(TC $ numeric ())),
455- ref_range_upper_lim_var = TC $ col(" lab_dataset_name" , TC $ numeric ()) | > TC $ flag(" optional" )
460+ ref_range_upper_lim_var = TC $ col(" lab_dataset_name" , TC $ numeric ()) | > TC $ flag(" optional" ),
461+ receiver_id = TC $ character () | > TC $ flag(" optional" )
456462) | > TC $ attach_docs(mod_edish_API_docs )
457463
458464check_mod_edish <- function (
459465 afmm , datasets , module_id , subject_level_dataset_name , lab_dataset_name , subjectid_var , arm_var , arm_default_vals ,
460466 visit_var , baseline_visit_val , lb_test_var , lb_test_choices , lb_test_default_x_val , lb_test_default_y_val ,
461- lb_result_var , ref_range_upper_lim_var
467+ lb_result_var , ref_range_upper_lim_var , receiver_id
462468 ) {
463469 warn <- CM $ container()
464470 err <- CM $ container()
@@ -467,7 +473,7 @@ check_mod_edish <- function(
467473 afmm , datasets ,
468474 module_id , subject_level_dataset_name , lab_dataset_name , subjectid_var , arm_var , arm_default_vals ,
469475 visit_var , baseline_visit_val , lb_test_var , lb_test_choices , lb_test_default_x_val , lb_test_default_y_val ,
470- lb_result_var , ref_range_upper_lim_var ,
476+ lb_result_var , ref_range_upper_lim_var , receiver_id ,
471477 warn , err
472478 )
473479
0 commit comments