-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add two example apps to showcase DDL and Custom transformation #177
base: dev
Are you sure you want to change the base?
Changes from all commits
a2b260b
e249509
08bee69
ff83143
7ed2cc5
984c15f
321879d
7869599
329e5fb
929f2df
91d4179
4b2f5a2
563be2e
b450042
fdc6e4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
source("renv/activate.R") |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
|
||
<!-- Generated by app_readme_template.Rmd and generate_app_readme.R: do not edit by hand--> | ||
|
||
# custom-transform app | ||
|
||
### Run the app yourself | ||
|
||
source("https://raw.github.com/insightsengineering/teal.gallery/main/_internal/utils/sourceme.R") | ||
|
||
# Run the app | ||
restore_and_run("custom-transform", package_repo = "https://insightsengineering.r-universe.dev") | ||
|
||
### View the deployed app | ||
|
||
Deployed app: | ||
<https://genentech.shinyapps.io/NEST_custom-transform_stable> | ||
|
||
### Preview the app | ||
|
||
![](../_internal/quarto/assets/img/custom-transform.gif)<!-- --> |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,132 @@ | ||||
library(teal) | ||||
|
||||
my_transformers <- list( | ||||
teal_transform_module( | ||||
label = "Keep first n-observations from IRIS", | ||||
ui = function(id) { | ||||
ns <- NS(id) | ||||
div( | ||||
checkboxInput(ns("check"), label = "Toggle `head(iris)`"), | ||||
) | ||||
}, | ||||
server = function(id, data) { | ||||
moduleServer(id, function(input, output, session) { | ||||
eventReactive(input$check, { | ||||
req(data()) | ||||
if (input$check) { | ||||
within(data(), iris <- head(iris, 6)) | ||||
} else { | ||||
data() | ||||
} | ||||
}) | ||||
}) | ||||
} | ||||
), | ||||
teal_transform_module( | ||||
label = "Merge datasets to get ANL", | ||||
ui = function(id) { | ||||
ns <- NS(id) | ||||
tagList( | ||||
div("Choose the two datasets to merge:"), | ||||
teal.widgets::optionalSelectInput(ns("merge_a"), "Merge A", choices = NULL), | ||||
teal.widgets::optionalSelectInput(ns("merge_b"), "Merge B", choices = NULL) | ||||
) | ||||
}, | ||||
server = function(id, data) { | ||||
checkmate::assert_class(data, "reactive") | ||||
moduleServer(id, function(input, output, session) { | ||||
iv <- shinyvalidate::InputValidator$new() | ||||
iv$add_rule("merge_a", shinyvalidate::sv_required("Please select dataset A")) | ||||
iv$add_rule("merge_b", shinyvalidate::sv_required("Please select dataset B")) | ||||
iv$enable() | ||||
|
||||
reactive_datanames <- reactive({ | ||||
req(data()) | ||||
teal.data::datanames(data()) | ||||
}) | ||||
observeEvent(reactive_datanames(), { | ||||
selected_a <- isolate(input$merge_a) | ||||
if (identical(selected_a, "")) selected_a <- restoreInput(session$ns("merge_a"), NULL) | ||||
teal.widgets::updateOptionalSelectInput( | ||||
session = session, | ||||
inputId = "merge_a", | ||||
choices = reactive_datanames(), | ||||
selected = restoreInput(session$ns("merge_a"), selected_a) | ||||
) | ||||
|
||||
selected_b <- isolate(input$merge_b) | ||||
if (identical(selected_b, "")) selected <- restoreInput(session$ns("merge_b"), NULL) | ||||
teal.widgets::updateOptionalSelectInput( | ||||
session = session, | ||||
inputId = "merge_b", | ||||
choices = reactive_datanames(), | ||||
selected = restoreInput(session$ns("merge_b"), selected_b) | ||||
) | ||||
}) | ||||
|
||||
reactive({ | ||||
req(input$merge_a, input$merge_b) | ||||
new_data <- within( | ||||
data(), | ||||
ANL <- dplyr::left_join(merge_a, merge_b), | ||||
merge_a = as.name(input$merge_a), | ||||
merge_b = as.name(input$merge_b) | ||||
) | ||||
teal.data::datanames(new_data) <- c(teal.data::datanames(new_data), "ANL") | ||||
new_data | ||||
}) | ||||
}) | ||||
} | ||||
) | ||||
) | ||||
|
||||
data <- teal_data() | ||||
data <- within(data, { | ||||
ADSL <- teal.data::rADSL | ||||
ADTTE <- teal.data::rADTTE | ||||
iris <- iris | ||||
CO2 <- CO2 | ||||
factors <- names(Filter(isTRUE, vapply(CO2, is.factor, logical(1L)))) | ||||
CO2[factors] <- lapply(CO2[factors], as.character) | ||||
}) | ||||
join_keys(data) <- default_cdisc_join_keys[c("ADSL", "ADTTE")] | ||||
teal.data::datanames(data) <- c("ADSL", "ADTTE", "iris", "CO2") | ||||
|
||||
nest_logo <- "https://raw.githubusercontent.com/insightsengineering/hex-stickers/main/PNG/nest.png" | ||||
app_source <- "https://github.com/insightsengineering/teal.gallery/tree/main/basic-teal" | ||||
gh_issues_page <- "https://github.com/insightsengineering/teal.gallery/issues" | ||||
|
||||
header <- tags$span( | ||||
style = "display: flex; align-items: center; justify-content: space-between; margin: 10px 0 10px 0;", | ||||
tags$span("Teal app with custom transform", style = "font-size: 30px;"), | ||||
tags$span( | ||||
style = "display: flex; align-items: center;", | ||||
tags$img(src = nest_logo, alt = "NEST logo", height = "45px", style = "margin-right:10px;"), | ||||
tags$span(style = "font-size: 24px;", "NEST @ Roche") | ||||
) | ||||
) | ||||
|
||||
footer <- tags$p( | ||||
"This teal app is brought to you by the NEST Team at Roche/Genentech. | ||||
For more information, please visit:", | ||||
tags$a(href = app_source, target = "_blank", "Source Code"), ", ", | ||||
tags$a(href = gh_issues_page, target = "_blank", "Report Issues") | ||||
) | ||||
Comment on lines
+95
to
+114
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a comment for this PR, but all apps code is extended by 20 lines just to add a NEST logo |
||||
|
||||
app <- init( | ||||
data = data, | ||||
filter = teal_slices( | ||||
teal_slice("ADSL", "SEX"), | ||||
teal_slice("ADSL", "AGE", selected = c(18L, 65L)) | ||||
), | ||||
modules = modules( | ||||
example_module("Module with transformations", transformers = my_transformers), | ||||
example_module("Module with only iris transformation", transformers = my_transformers[1]), | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it really needed?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's okay to have this. Without this, we would have one module with transformers and one without it. Adding a transformation using the same object clears some misconceptions some people might have. For example, the |
||||
example_module("Module with no transformations") | ||||
), | ||||
title = build_app_title("Custom Transform Teal App", nest_logo), | ||||
header = header, | ||||
footer = footer | ||||
) | ||||
|
||||
shinyApp(app$ui, app$server) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Version: 1.0 | ||
|
||
RestoreWorkspace: Default | ||
SaveWorkspace: Default | ||
AlwaysSaveHistory: Default | ||
|
||
EnableCodeIndexing: Yes | ||
UseSpacesForTab: Yes | ||
NumSpacesForTab: 2 | ||
Encoding: UTF-8 | ||
|
||
RnwWeave: Sweave | ||
LaTeX: pdfLaTeX | ||
|
||
AutoAppendNewline: Yes | ||
StripTrailingWhitespace: Yes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should revert the branch checkout before merging. This was changed just to test the deployment.