Skip to content
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 roxy.shinylive to DESCRIPTION and vignettes, update NEWS #249

Merged
merged 3 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Imports:
Suggests:
knitr (>= 1.42),
rmarkdown (>= 2.23),
roxy.shinylive,
donyunardi marked this conversation as resolved.
Show resolved Hide resolved
testthat (>= 3.1.5),
withr (>= 2.0.0)
VignetteBuilder:
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
29 changes: 23 additions & 6 deletions vignettes/data-extract-merge.Rmd
donyunardi marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand All @@ -175,4 +175,21 @@ shinyApp(
)
```

<img src="images/app-data-extract-merge.png" alt="Shiny app output for Data Extract and Merge" style="width: 100%;" />
## 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")
```
26 changes: 21 additions & 5 deletions vignettes/data-extract.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")),
Expand All @@ -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(
Expand Down Expand Up @@ -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) {
Expand All @@ -115,4 +115,20 @@ shinyApp(
)
```

<img src="images/app-data-extract.png" alt="Shiny app output for Data Extract" style="width: 100%;" />
## 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")
```
47 changes: 38 additions & 9 deletions vignettes/data-merge.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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) {
Expand All @@ -149,8 +149,22 @@ shinyApp(
)
```

<img src="images/app-data-merge-1.png" alt="Shiny app output for Data Extract" style="width: 100%;" />
```{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")
```

<hr>

Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -203,7 +217,22 @@ shinyApp(
)
```

<img src="images/app-data-merge-2.png" alt="Shiny app output for Data Extract" style="width: 100%;" />
```{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:

Expand Down
Loading