1- tm_p_swimlane <- function (label = " Swimlane Plot Module" , dataname , id_var , avisit_var , shape_var , color_var ) {
1+ tm_p_swimlane <- function (label = " Swimlane Plot Module" , geom_specs , title , color_manual , shape_manual , size_manual ) {
22 module(
33 label = label ,
44 ui = ui_p_swimlane ,
55 server = srv_p_swimlane ,
6- datanames = " synthetic_data " ,
6+ datanames = " all " ,
77 server_args = list (
8- dataname = dataname ,
9- id_var = id_var ,
10- avisit_var = avisit_var ,
11- shape_var = shape_var ,
12- color_var = color_var
8+ geom_specs = geom_specs , title = title ,
9+ color_manual = color_manual , shape_manual = shape_manual , size_manual = size_manual
1310 )
1411 )
1512}
@@ -22,30 +19,44 @@ ui_p_swimlane <- function(id) {
2219 )
2320}
2421
25- srv_p_swimlane <- function (id , data , dataname , id_var , avisit_var , shape_var , color_var , filter_panel_api ) {
22+ srv_p_swimlane <- function (id ,
23+ data ,
24+ geom_specs ,
25+ title = " Swimlane plot" ,
26+ color_manual ,
27+ shape_manual ,
28+ size_manual ,
29+ filter_panel_api ) {
2630 moduleServer(id , function (input , output , session ) {
27- output_q <- reactive({
28- within(data(),
29- {
30- p <- ggplot(dataname , aes(x = avisit_var , y = subjid )) +
31- ggtitle(" Swimlane Efficacy Table" ) +
32- geom_line(linewidth = 0.5 ) +
33- geom_point(aes(shape = shape_var ), size = 5 ) +
34- geom_point(aes(color = color_var ), size = 2 ) +
35- scale_shape_manual(values = c(" Drug A" = 1 , " Drug B" = 2 )) +
36- scale_color_manual(values = c(" CR" = " #9b59b6" , " PR" = " #3498db" )) +
37- labs(x = " Study Day" , y = " Subject ID" )
38- },
39- dataname = as.name(dataname ),
40- id_var = as.name(id_var ),
41- avisit_var = as.name(avisit_var ),
42- shape_var = as.name(shape_var ),
43- color_var = as.name(color_var )
31+ ggplot_call <- reactive({
32+ plot_call <- bquote(ggplot2 :: ggplot())
33+ points_calls <- lapply(geom_specs , function (x ) {
34+ # todo: convert $geom, $data, and $mapping elements from character to language
35+ # others can be kept as character
36+ basic_call <- as.call(
37+ c(
38+ list (
39+ x $ geom ,
40+ mapping = as.call(c(as.name(" aes" ), x $ mapping ))
41+ ),
42+ x [! names(x ) %in% c(" geom" , " mapping" )]
43+ )
44+ )
45+ })
46+
47+ title_call <- substitute(ggtitle(title ), list (title = title ))
48+
49+ rhs <- Reduce(
50+ x = c(plot_call , points_calls , title_call ),
51+ f = function (x , y ) call(" +" , x , y )
4452 )
53+ substitute(p <- rhs , list (rhs = rhs ))
4554 })
4655
56+ output_q <- reactive(eval_code(data(), ggplot_call()))
57+
4758 plot_r <- reactive(output_q()$ p )
48- pws <- teal.widgets :: plot_with_settings_srv(id = " myplot" , plot_r = plot_r )
59+ pws <- teal.widgets :: plot_with_settings_srv(id = " myplot" , plot_r = plot_r , gg2plotly = FALSE )
4960
5061 teal :: srv_brush_filter(
5162 " brush_filter" ,
@@ -55,3 +66,9 @@ srv_p_swimlane <- function(id, data, dataname, id_var, avisit_var, shape_var, co
5566 )
5667 })
5768}
69+
70+
71+
72+ merge_selectors2 <- function () {
73+ lappl
74+ }
0 commit comments