Skip to content

Commit

Permalink
feat: add example using the poc data
Browse files Browse the repository at this point in the history
  • Loading branch information
vedhav committed Nov 19, 2024
1 parent 4038ba8 commit 06bf0a4
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 13 deletions.
16 changes: 3 additions & 13 deletions R/tm_p_swimlane.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
tm_p_swimlane <- function(label = "Swimlane Plot Module",
geom_specs,
title,
color_manual = NULL,
shape_manual = NULL,
size_manual = NULL) {
tm_p_swimlane <- function(label = "Swimlane Plot Module", geom_specs, title) {
module(
label = label,
ui = ui_p_swimlane,
server = srv_p_swimlane,
datanames = "all",
server_args = list(
geom_specs = geom_specs, title = title,
color_manual = color_manual, shape_manual = shape_manual, size_manual = size_manual
geom_specs = geom_specs,
title = title
)
)
}
Expand All @@ -28,9 +23,6 @@ srv_p_swimlane <- function(id,
data,
geom_specs,
title = "Swimlane plot",
color_manual,
shape_manual,
size_manual,
filter_panel_api) {
moduleServer(id, function(input, output, session) {
ggplot_call <- reactive({
Expand Down Expand Up @@ -72,8 +64,6 @@ srv_p_swimlane <- function(id,
})
}



merge_selectors2 <- function() {
lappl
}
112 changes: 112 additions & 0 deletions inst/poc_crf.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
pkgload::load_all("teal")
pkgload::load_all("teal.widgets")
pkgload::load_all("teal.modules.general")

# Example data
data <- within(teal_data(), {
library(dplyr)
library(arrow)
library(forcats)
data_path <- "PATH_TO_DATA"

swimlane_ds <- read_parquet(file.path(data_path, "swimlane_ds.parquet")) |>
filter(!is.na(event_result), !is.na(event_study_day)) |>
mutate(subject = forcats::fct_reorder(as.factor(subject), event_study_day, .fun = max))
disposition <- swimlane_ds |>
filter(!is.na(event_study_day)) |>
filter(event_type == "disposition") |>
transmute(subject, event_type, catagory = event_result, study_day = event_study_day)

response_assessment <- swimlane_ds |>
filter(!is.na(event_study_day)) |>
filter(event_type == "response_assessment") |>
transmute(subject, event_type, catagory = event_result, study_day = event_study_day)

study_drug_administration <- swimlane_ds |>
filter(!is.na(event_study_day)) |>
filter(event_type == "study_drug_administration") |>
transmute(subject, event_type, catagory = event_result, study_day = event_study_day)

max_subject_day <- swimlane_ds |>
group_by(subject) |>
summarise(max_study_day = max(event_study_day))
})

color_manual <- c(
"DEATH" = "black",
"WITHDRAWAL BY SUBJECT" = "grey",
"PD (Progressive Disease)" = "red",
"SD (Stable Disease)" = "darkorchid4",
"MR (Minimal/Minor Response)" = "sienna4",
"PR (Partial Response)" = "maroon",
"VGPR (Very Good Partial Response)" = "chartreuse4",
"CR (Complete Response)" = "#3a41fc",
"SCR (Stringent Complete Response)" = "midnightblue"
)
shape_manual <- c(
"DEATH" = 4,
"WITHDRAWAL BY SUBJECT" = 5,
"PD (Progressive Disease)" = 8,
"SD (Stable Disease)" = 5,
"MR (Minimal/Minor Response)" = 5,
"PR (Partial Response)" = 5,
"VGPR (Very Good Partial Response)" = 5,
"CR (Complete Response)" = 5,
"SCR (Stringent Complete Response)" = 5
)

app <- init(
data = data,
modules = modules(
tm_data_table(),
tm_p_swimlane(
label = "Swimlane",
geom_specs = list(
list(
geom = str2lang("ggplot2::geom_bar"),
data = quote(max_subject_day),
mapping = list(y = quote(subject), x = quote(max_study_day)),
stat = "identity",
width = 0.1
),
list(
geom = quote(geom_point),
data = quote(study_drug_administration),
mapping = list(
y = quote(subject), x = quote(study_day), color = quote(catagory), shape = quote(catagory)
)
),
list(
geom = quote(geom_point),
data = quote(disposition),
mapping = list(
y = quote(subject), x = quote(study_day), color = quote(catagory), shape = quote(catagory)
)
),
list(
geom = quote(geom_point),
data = quote(response_assessment),
mapping = list(
y = quote(subject), x = quote(study_day), color = quote(catagory), shape = quote(catagory)
)
),
list(
geom = quote(scale_color_manual),
values = color_manual,
breaks = names(color_manual)
),
list(
geom = quote(scale_shape_manual),
values = shape_manual,
breaks = names(shape_manual)
),
list(
geom = quote(theme_minimal)
)
),
title = "Swimlane Efficacy Plot"
)
)
)

shinyApp(app$ui, app$server)

0 comments on commit 06bf0a4

Please sign in to comment.