diff --git a/DESCRIPTION b/DESCRIPTION index 0abe49c1..9c7d1ad3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,6 +40,7 @@ Imports: Suggests: knitr (>= 1.42), rmarkdown (>= 2.23), + roxy.shinylive (>= 1.0.0), testthat (>= 3.1.5), withr (>= 2.0.0) VignetteBuilder: diff --git a/NEWS.md b/NEWS.md index bf77e244..b5913f5d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,8 @@ * Added utility functions `first_choice`, `last_choice`, `first_choices`, and `last_choices` to increase the repertoire of specifying choices in delayed data, previously only served by `all_choices`. * Allowed `value_choices` to use `delayed_variable_choices` objects for `var_choices`. It is now possible to define a `data_extract_spec` without naming any variables. +* Replace the example data generated using `scda` with `random.cdisc.data`. +* Change log level from trace to debug for several functions. # teal.transform 0.5.0 diff --git a/vignettes/data-extract-merge.Rmd b/vignettes/combining-data-extract-with-data-merge.Rmd similarity index 87% rename from vignettes/data-extract-merge.Rmd rename to vignettes/combining-data-extract-with-data-merge.Rmd index 67122847..6df56836 100644 --- a/vignettes/data-extract-merge.Rmd +++ b/vignettes/combining-data-extract-with-data-merge.Rmd @@ -34,7 +34,7 @@ Let's see how to achieve this dynamic `select`, `filter`, and `merge` operations #### Step 1/5 - Preparing the Data -```{r} +```{r library} library(teal.transform) library(teal.data) library(shiny) @@ -68,7 +68,7 @@ It is created by the `data_extract_spec()` function which takes in four argument 3. `filter` helps specify the values of a variable we wish to filter during extraction. It can be generated using the function `filter_spec()`. In the case of `ADTTE`, we filter the variable `PARAMCD` by allowing users to choose from `CRSD`, `EFS`, `OS`, and `PFS`, with `OS` being the default filter. 4. `reshape` is a boolean which helps to specify if the data needs to be reshaped from long to wide format. By default it is set to `FALSE`. -```{r} +```{r data_extract_spec} adsl_extract <- data_extract_spec( dataname = "ADSL", select = select_spec( @@ -104,7 +104,7 @@ Here, we define the `merge_ui` function, which will be used to create the UI com Note that we take in the list of `data_extract` objects as input, and make use of the `data_extract_ui` function to create our UI. -```{r} +```{r merge_ui} merge_ui <- function(id, data_extracts) { ns <- NS(id) sidebarLayout( @@ -140,7 +140,7 @@ This function takes as arguments the datasets (as a list of reactive `data.frame We make use of the `merge_expression_srv` function to get a reactive list containing merge expression and information needed to perform the transformation - see more in `merge_expression_srv` documentation. We print this expression in the UI and also evaluate it to get the final `ANL` dataset which is also displayed as a table in the UI. -```{r} +```{r merge_srv} merge_srv <- function(id, datasets, data_extracts, join_keys) { moduleServer(id, function(input, output, session) { selector_list <- data_extract_multiple_srv(data_extracts, datasets, join_keys) @@ -166,7 +166,7 @@ merge_srv <- function(id, datasets, data_extracts, join_keys) { Finally, we include `merge_ui` and `merge_srv` in the UI and server components of the `shinyApp`, respectively, using the `data_extract`s defined in the first code block and the `datasets` object: -```{r eval=FALSE} +```{r shinyapp, eval=FALSE} shinyApp( ui = fluidPage(merge_ui("data_merge", data_extracts)), server = function(input, output, session) { @@ -175,4 +175,21 @@ shinyApp( ) ``` -Shiny app output for Data Extract and Merge +## Try it out in Shinylive + +```{r shinylive_url, echo = FALSE, results = 'asis', eval = requireNamespace("roxy.shinylive", quietly = TRUE)} +code <- paste0(c( + knitr::knit_code$get("library"), + knitr::knit_code$get("data_extract_spec"), + knitr::knit_code$get("merge_ui"), + knitr::knit_code$get("merge_srv"), + knitr::knit_code$get("shinyapp") +), collapse = "\n") + +url <- roxy.shinylive::create_shinylive_url(code) +cat(sprintf("[Open in Shinylive](%s)\n\n", url)) +``` + +```{r shinylive_iframe, echo = FALSE, out.width = '150%', out.extra = 'style = "position: relative; z-index:1"', eval = requireNamespace("roxy.shinylive", quietly = TRUE) && knitr::is_html_output() && identical(Sys.getenv("IN_PKGDOWN"), "true")} +knitr::include_url(url, height = "800px") +``` diff --git a/vignettes/data-extract.Rmd b/vignettes/data-extract.Rmd index cbe47574..8207753f 100644 --- a/vignettes/data-extract.Rmd +++ b/vignettes/data-extract.Rmd @@ -31,7 +31,7 @@ Let's delve into how it fulfills both of these responsibilities. #### Step 1/4 - Preparing the Data -```{r} +```{r library} library(teal.transform) library(teal.data) library(shiny) @@ -59,7 +59,7 @@ Consider the following example, where we create two UI elements, one to filter o and a second one to select a variable from `c("BMRKR1", "AGE")`. `data_extract_spec` object is handed over to the `shiny` app and gives instructions to generate UI components. -```{r} +```{r data_extract_spec} simple_des <- data_extract_spec( dataname = "ADSL", filter = filter_spec(vars = "SEX", choices = c("F", "M")), @@ -74,7 +74,7 @@ utilizes `data_extract_ui` and `data_extract_srv` to handle `data_extract_spec` This module creates a UI component for a single `data_extract_spec` and prints a list of values returned from the `data_extract_srv` module. For more information about `data_extract_ui` and `data_extract_srv`, please refer to the package documentation. -```{r} +```{r extract_ui_srv} extract_ui <- function(id, data_extract) { ns <- NS(id) sidebarLayout( @@ -106,7 +106,7 @@ extract_srv <- function(id, datasets, data_extract, join_keys) { Finally, we include `extract_ui` in the UI of the `shinyApp`, and utilize `extract_srv` in the server function of the `shinyApp`: -```{r eval=FALSE} +```{r shinyapp, eval=FALSE} shinyApp( ui = fluidPage(extract_ui("data_extract", simple_des)), server = function(input, output, session) { @@ -115,4 +115,20 @@ shinyApp( ) ``` -Shiny app output for Data Extract +## Try it out in Shinylive + +```{r shinylive_url, echo = FALSE, results = 'asis', eval = requireNamespace("roxy.shinylive", quietly = TRUE)} +code <- paste0(c( + knitr::knit_code$get("library"), + knitr::knit_code$get("data_extract_spec"), + knitr::knit_code$get("extract_ui_srv"), + knitr::knit_code$get("shinyapp") +), collapse = "\n") + +url <- roxy.shinylive::create_shinylive_url(code) +cat(sprintf("[Open in Shinylive](%s)\n\n", url)) +``` + +```{r shinylive_iframe, echo = FALSE, out.width = '150%', out.extra = 'style = "position: relative; z-index:1"', eval = requireNamespace("roxy.shinylive", quietly = TRUE) && knitr::is_html_output() && identical(Sys.getenv("IN_PKGDOWN"), "true")} +knitr::include_url(url, height = "800px") +``` diff --git a/vignettes/data-merge.Rmd b/vignettes/data-merge.Rmd index e62b959b..03d36c6f 100644 --- a/vignettes/data-merge.Rmd +++ b/vignettes/data-merge.Rmd @@ -35,7 +35,7 @@ a list of reactive or non-reactive `data.frame` objects, and a list of join keys #### Step 1/5 - Preparing the Data -```{r} +```{r library} library(teal.transform) library(teal.data) library(shiny) @@ -61,7 +61,7 @@ join_keys <- join_keys( #### Step 2/5 - Creating the Data Extracts -```{r} +```{r data_extract_spec} adsl_extract <- data_extract_spec( dataname = "ADSL", select = select_spec( @@ -88,7 +88,7 @@ data_extracts <- list(adsl_extract = adsl_extract, adtte_extract = adtte_extract #### Step 3/5 - Creating the UI -```{r} +```{r merge_ui} merge_ui <- function(id, data_extracts) { ns <- NS(id) sidebarLayout( @@ -118,7 +118,7 @@ merge_ui <- function(id, data_extracts) { #### Step 4/5 - Creating the Server Logic -```{r} +```{r merge_srv} merge_srv <- function(id, datasets, data_extracts, join_keys) { moduleServer(id, function(input, output, session) { merged_data <- merge_expression_module( @@ -140,7 +140,7 @@ merge_srv <- function(id, datasets, data_extracts, join_keys) { #### Step 5/5 - Creating the `shiny` App -```{r eval=FALSE} +```{r shinyapp, eval=FALSE} shinyApp( ui = fluidPage(merge_ui("data_merge", data_extracts)), server = function(input, output, session) { @@ -149,8 +149,22 @@ shinyApp( ) ``` -Shiny app output for Data Extract +```{r shinylive_url, echo = FALSE, results = 'asis', eval = requireNamespace("roxy.shinylive", quietly = TRUE)} +code <- paste0(c( + knitr::knit_code$get("library"), + knitr::knit_code$get("data_extract_spec"), + knitr::knit_code$get("merge_ui"), + knitr::knit_code$get("merge_srv"), + knitr::knit_code$get("shinyapp") +), collapse = "\n") + +url <- roxy.shinylive::create_shinylive_url(code) +cat(sprintf("[Open in Shinylive](%s)\n\n", url)) +``` +```{r shinylive_iframe, echo = FALSE, out.width = '150%', out.extra = 'style = "position: relative; z-index:1"', eval = requireNamespace("roxy.shinylive", quietly = TRUE) && knitr::is_html_output() && identical(Sys.getenv("IN_PKGDOWN"), "true")} +knitr::include_url(url, height = "800px") +```
@@ -163,7 +177,7 @@ The `reactive_selector_list` is then passed to `merge_expression_srv`: #### Modifying the Server Logic -```{r} +```{r merge_srv2} merge_srv <- function(id, datasets, data_extracts, join_keys) { moduleServer(id, function(input, output, session) { selector_list <- data_extract_multiple_srv(data_extracts, datasets, join_keys) @@ -194,7 +208,7 @@ merge_srv <- function(id, datasets, data_extracts, join_keys) { #### Updating the `shiny` app -```{r eval=FALSE} +```{r shinyapp2, eval=FALSE} shinyApp( ui = fluidPage(merge_ui("data_merge", data_extracts)), server = function(input, output, session) { @@ -203,7 +217,22 @@ shinyApp( ) ``` -Shiny app output for Data Extract +```{r shinylive_url2, echo = FALSE, results = 'asis', eval = requireNamespace("roxy.shinylive", quietly = TRUE)} +code <- paste0(c( + knitr::knit_code$get("library"), + knitr::knit_code$get("data_extract_spec"), + knitr::knit_code$get("merge_ui"), + knitr::knit_code$get("merge_srv2"), + knitr::knit_code$get("shinyapp2") +), collapse = "\n") + +url <- roxy.shinylive::create_shinylive_url(code) +cat(sprintf("[Open in Shinylive](%s)\n\n", url)) +``` + +```{r shinylive_iframe2, echo = FALSE, out.width = '150%', out.extra = 'style = "position: relative; z-index:1"', eval = requireNamespace("roxy.shinylive", quietly = TRUE) && knitr::is_html_output() && identical(Sys.getenv("IN_PKGDOWN"), "true")} +knitr::include_url(url, height = "800px") +``` `merge_expression_module` is replaced here with three parts: