Skip to content

Commit 67d4a5c

Browse files
committed
wip
1 parent c5c744d commit 67d4a5c

File tree

2 files changed

+68
-33
lines changed

2 files changed

+68
-33
lines changed

R/tm_p_swimlane.R

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
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+
}

inst/swimlane_poc.R

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,32 @@ app <- init(
3636
modules = modules(
3737
tm_data_table(),
3838
tm_p_swimlane(
39-
dataname = "synthetic_data",
40-
id_var = "usubjid",
41-
avisit_var = "study_day",
42-
shape_var = "assigned_drug",
43-
color_var = "response_type"
39+
label = "Swimlane",
40+
geom_specs = list(
41+
list(
42+
geom = str2lang("ggplot2::geom_col"),
43+
data = quote(synthetic_data),
44+
mapping = list(y = quote(subjid), x = quote(max(study_day))),
45+
width = 0.2
46+
), # geom_col(data = synthetic_data, mapping = aes(x = subjid, x = max(study_day), width = 0.2)
47+
list(
48+
geom = quote(geom_point),
49+
data = quote(synthetic_data),
50+
mapping = list(
51+
y = quote(subjid), x = quote(study_day), color = quote(assigned_drug), shape = quote(assigned_drug)
52+
)
53+
),
54+
list(
55+
geom = quote(geom_point),
56+
data = quote(synthetic_data),
57+
mapping = list(
58+
y = quote(subjid), x = quote(study_day), color = quote(response_type), shape = quote(response_type)
59+
)
60+
)
61+
),
62+
title = "Swimlane Efficacy Plot"
4463
)
45-
),
46-
title = "Swimlane Efficacy Plot"
64+
)
4765
)
4866

4967
shinyApp(app$ui, app$server)

0 commit comments

Comments
 (0)