|
| 1 | +tm_p_swimlane <- function(label = "Swimlane Plot Module", dataname, id_var, avisit_var, shape_var, color_var) { |
| 2 | + module( |
| 3 | + label = label, |
| 4 | + ui = ui_p_swimlane, |
| 5 | + server = srv_p_swimlane, |
| 6 | + datanames = "synthetic_data", |
| 7 | + 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 |
| 13 | + ) |
| 14 | + ) |
| 15 | +} |
| 16 | + |
| 17 | +ui_p_swimlane <- function(id) { |
| 18 | + ns <- NS(id) |
| 19 | + shiny::tagList( |
| 20 | + teal.widgets::plot_with_settings_ui(ns("myplot")), |
| 21 | + teal::ui_brush_filter(ns("brush_filter")) |
| 22 | + ) |
| 23 | +} |
| 24 | + |
| 25 | +srv_p_swimlane <- function(id, data, dataname, id_var, avisit_var, shape_var, color_var, filter_panel_api) { |
| 26 | + 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) |
| 44 | + ) |
| 45 | + }) |
| 46 | + |
| 47 | + plot_r <- reactive(output_q()$p) |
| 48 | + pws <- teal.widgets::plot_with_settings_srv(id = "myplot", plot_r = plot_r) |
| 49 | + |
| 50 | + teal::srv_brush_filter( |
| 51 | + "brush_filter", |
| 52 | + brush = pws$brush, |
| 53 | + dataset = reactive(teal.code::dev_suppress(output_q()$synthetic_data)), |
| 54 | + filter_panel_api = filter_panel_api |
| 55 | + ) |
| 56 | + }) |
| 57 | +} |
0 commit comments