Skip to content

Commit 4b987a6

Browse files
committed
WIP
swimlane POC
1 parent bf7b4c4 commit 4b987a6

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

R/tm_p_swimlane.R

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

inst/swimlane_poc.R

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
pkgload::load_all("teal")
2+
pkgload::load_all("teal.widgets")
3+
pkgload::load_all("teal.modules.general")
4+
5+
6+
# Example data
7+
data <- within(teal_data(), {
8+
library(dplyr)
9+
library(tidyr)
10+
11+
set.seed(123) # Setting a seed for reproducibility
12+
# Define possible maximum study days
13+
.possible_end_days <- c(50, 60, 70)
14+
15+
# Create sample data
16+
synthetic_data <- tibble(subjid = c(1:15)) |>
17+
rowwise() |>
18+
mutate(
19+
max_study_day = sample(.possible_end_days, 1),
20+
study_day = list(seq(10, max_study_day, by = 10))
21+
) |>
22+
unnest(study_day) |>
23+
group_by(subjid) |>
24+
mutate(
25+
assigned_drug = sample(c("Drug A", "Drug B"), 1)
26+
) |>
27+
ungroup() |>
28+
mutate(
29+
response_type = sample(c("CR", "PR"), n(), replace = TRUE),
30+
subjid = reorder(as.character(subjid), max_study_day)
31+
) |>
32+
select(-max_study_day)
33+
})
34+
35+
app <- init(
36+
data = data,
37+
modules = modules(
38+
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"
44+
)
45+
),
46+
title = "Swimlane Efficacy Plot"
47+
)
48+
49+
shinyApp(app$ui, app$server)

0 commit comments

Comments
 (0)