Skip to content

Commit 06bf0a4

Browse files
committed
feat: add example using the poc data
1 parent 4038ba8 commit 06bf0a4

File tree

2 files changed

+115
-13
lines changed

2 files changed

+115
-13
lines changed

R/tm_p_swimlane.R

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
tm_p_swimlane <- function(label = "Swimlane Plot Module",
2-
geom_specs,
3-
title,
4-
color_manual = NULL,
5-
shape_manual = NULL,
6-
size_manual = NULL) {
1+
tm_p_swimlane <- function(label = "Swimlane Plot Module", geom_specs, title) {
72
module(
83
label = label,
94
ui = ui_p_swimlane,
105
server = srv_p_swimlane,
116
datanames = "all",
127
server_args = list(
13-
geom_specs = geom_specs, title = title,
14-
color_manual = color_manual, shape_manual = shape_manual, size_manual = size_manual
8+
geom_specs = geom_specs,
9+
title = title
1510
)
1611
)
1712
}
@@ -28,9 +23,6 @@ srv_p_swimlane <- function(id,
2823
data,
2924
geom_specs,
3025
title = "Swimlane plot",
31-
color_manual,
32-
shape_manual,
33-
size_manual,
3426
filter_panel_api) {
3527
moduleServer(id, function(input, output, session) {
3628
ggplot_call <- reactive({
@@ -72,8 +64,6 @@ srv_p_swimlane <- function(id,
7264
})
7365
}
7466

75-
76-
7767
merge_selectors2 <- function() {
7868
lappl
7969
}

inst/poc_crf.R

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
pkgload::load_all("teal")
2+
pkgload::load_all("teal.widgets")
3+
pkgload::load_all("teal.modules.general")
4+
5+
# Example data
6+
data <- within(teal_data(), {
7+
library(dplyr)
8+
library(arrow)
9+
library(forcats)
10+
data_path <- "PATH_TO_DATA"
11+
12+
swimlane_ds <- read_parquet(file.path(data_path, "swimlane_ds.parquet")) |>
13+
filter(!is.na(event_result), !is.na(event_study_day)) |>
14+
mutate(subject = forcats::fct_reorder(as.factor(subject), event_study_day, .fun = max))
15+
disposition <- swimlane_ds |>
16+
filter(!is.na(event_study_day)) |>
17+
filter(event_type == "disposition") |>
18+
transmute(subject, event_type, catagory = event_result, study_day = event_study_day)
19+
20+
response_assessment <- swimlane_ds |>
21+
filter(!is.na(event_study_day)) |>
22+
filter(event_type == "response_assessment") |>
23+
transmute(subject, event_type, catagory = event_result, study_day = event_study_day)
24+
25+
study_drug_administration <- swimlane_ds |>
26+
filter(!is.na(event_study_day)) |>
27+
filter(event_type == "study_drug_administration") |>
28+
transmute(subject, event_type, catagory = event_result, study_day = event_study_day)
29+
30+
max_subject_day <- swimlane_ds |>
31+
group_by(subject) |>
32+
summarise(max_study_day = max(event_study_day))
33+
})
34+
35+
color_manual <- c(
36+
"DEATH" = "black",
37+
"WITHDRAWAL BY SUBJECT" = "grey",
38+
"PD (Progressive Disease)" = "red",
39+
"SD (Stable Disease)" = "darkorchid4",
40+
"MR (Minimal/Minor Response)" = "sienna4",
41+
"PR (Partial Response)" = "maroon",
42+
"VGPR (Very Good Partial Response)" = "chartreuse4",
43+
"CR (Complete Response)" = "#3a41fc",
44+
"SCR (Stringent Complete Response)" = "midnightblue"
45+
)
46+
shape_manual <- c(
47+
"DEATH" = 4,
48+
"WITHDRAWAL BY SUBJECT" = 5,
49+
"PD (Progressive Disease)" = 8,
50+
"SD (Stable Disease)" = 5,
51+
"MR (Minimal/Minor Response)" = 5,
52+
"PR (Partial Response)" = 5,
53+
"VGPR (Very Good Partial Response)" = 5,
54+
"CR (Complete Response)" = 5,
55+
"SCR (Stringent Complete Response)" = 5
56+
)
57+
58+
app <- init(
59+
data = data,
60+
modules = modules(
61+
tm_data_table(),
62+
tm_p_swimlane(
63+
label = "Swimlane",
64+
geom_specs = list(
65+
list(
66+
geom = str2lang("ggplot2::geom_bar"),
67+
data = quote(max_subject_day),
68+
mapping = list(y = quote(subject), x = quote(max_study_day)),
69+
stat = "identity",
70+
width = 0.1
71+
),
72+
list(
73+
geom = quote(geom_point),
74+
data = quote(study_drug_administration),
75+
mapping = list(
76+
y = quote(subject), x = quote(study_day), color = quote(catagory), shape = quote(catagory)
77+
)
78+
),
79+
list(
80+
geom = quote(geom_point),
81+
data = quote(disposition),
82+
mapping = list(
83+
y = quote(subject), x = quote(study_day), color = quote(catagory), shape = quote(catagory)
84+
)
85+
),
86+
list(
87+
geom = quote(geom_point),
88+
data = quote(response_assessment),
89+
mapping = list(
90+
y = quote(subject), x = quote(study_day), color = quote(catagory), shape = quote(catagory)
91+
)
92+
),
93+
list(
94+
geom = quote(scale_color_manual),
95+
values = color_manual,
96+
breaks = names(color_manual)
97+
),
98+
list(
99+
geom = quote(scale_shape_manual),
100+
values = shape_manual,
101+
breaks = names(shape_manual)
102+
),
103+
list(
104+
geom = quote(theme_minimal)
105+
)
106+
),
107+
title = "Swimlane Efficacy Plot"
108+
)
109+
)
110+
)
111+
112+
shinyApp(app$ui, app$server)

0 commit comments

Comments
 (0)