|
| 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