diff --git a/vignettes/blockr_examples.Rmd b/vignettes/blockr_examples.Rmd index 85a596ba..160ebba9 100644 --- a/vignettes/blockr_examples.Rmd +++ b/vignettes/blockr_examples.Rmd @@ -57,26 +57,7 @@ ui_input.slider_field <- function(x, id, name) { #' @method validate_field slider_field #' @export validate_field.slider_field <- function(x) { - val <- value(x) - min <- value(x, "min") - max <- value(x, "max") - step <- value(x, "step") - - validate_number(val) - - if (length(min)) { - validate_number(min, "min") - } - - if (length(max)) { - validate_number(max, "max") - } - - if (length(step)) { - validate_number(step, "step") - } - - NextMethod() + x } #' @method ui_update slider_field @@ -145,13 +126,14 @@ blockr::register_block( In this example, we'll create a pipeline that fetches recent stock data using the [quantmod package](https://github.com/joshuaulrich/quantmod), performs time series analysis, and forecasts future stock prices using the [Prophet model](https://github.com/facebook/prophet). We first design the `stock_data_block`, containing a field to select the stock items and generate the data. The `prophet_forecast_block` does all the modeling part. -```{r stock_example} +```{r stock_example, eval=FALSE} +# Does not run on shinylive as quantmod/prophet not available library(blockr) library(quantmod) library(prophet) # Custom block to fetch stock data -stock_data_block <- function(...) { +new_stock_data_block <- function(...) { # stocks to pick (top 10) pick_stock <- \() c("NVDA", "TSLA", "AAPL", "MSFT", "AVGO", "AMZN", "AMD", "PLTR", "TSM", "META") @@ -171,7 +153,7 @@ stock_data_block <- function(...) { } # Custom block for Prophet forecasting -prophet_forecast_block <- function(columns = character(), ...) { +new_prophet_forecast_block <- function(columns = character(), ...) { all_cols <- function(data) colnames(data)[2:length(colnames(data))] @@ -198,7 +180,7 @@ prophet_forecast_block <- function(columns = character(), ...) { # Register custom blocks register_block( - stock_data_block, + new_stock_data_block, name = "Stock Data", description = "Fetch stock data", classes = c("stock_data_block", "data_block"), @@ -206,7 +188,7 @@ register_block( output = "data.frame" ) register_block( - prophet_forecast_block, + new_prophet_forecast_block, name = "Prophet Forecast", description = "Forecast using Prophet", classes = c("prophet_forecast_block", "plot_block"), @@ -216,13 +198,16 @@ register_block( # Create the stack stock_forecast_stack <- new_stack( - stock_data_block(), - prophet_forecast_block() + new_stock_data_block(), + new_prophet_forecast_block() ) serve_stack(stock_forecast_stack) ``` - + +```{r blockr-stock, echo=FALSE, fig.cap='Stock model demo', fig.align = 'center', out.width='100%'} +knitr::include_graphics("vignettes/figures/blockr-stock-demo.png") +``` ### 2. Pharmaceutical: Clinical Trial Analysis @@ -230,10 +215,36 @@ serve_stack(stock_forecast_stack) This forest plot visualizes the relative risk of adverse events between two treatment arms in a clinical trial. In this case, it compares "Xanomeline High Dose" to "Xanomeline Low Dose" starting from the [pharmaverseadam](https://github.com/pharmaverse/pharmaverseadam) `adae` dataset. -```{r ae_forest} +```{r, eval=TRUE, echo=FALSE} +card( + create_app_link( + "NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAdzgCMAnRRASwgGdSoAbbgCgA6YOtyIEA1gyG4ABAzioi7GQF4ZBQWAAWpUqnaIA9IZFjJAWiIMA5hmstSWgK50MLIodqNz8xe2kyQjp6Bsa+RBgM5tRQ7DAYVtZCAJTJAhBeTKwcXLyaphIMGKhaUAwwUABucAzscFAAJrAB4cpqGkG6+kYmooWWNnYOzq7unvRRrQGdIT3hkdGx8YkpaRDp3CyMZQCefAWSa5vbDHsNqNw7DEdbDLt8pCwNVzcnewBmVnCcF0Skr3dTvs+pJiqVylUanVGrA1ukAMQyABiTggBEeJBkpCI6nkUHIMka1VqcBkcGqZBkn3knBkv1I6QIePIAH0oHAWdTvqQWfSZAAecxU1Ho9wQPhNLiyJzsFwAKyeLOI3FkZRgSqIKsJcAacGIDQ1WogLPJFFI7GSMhA6RkMklUAFQvtMgAPgA+KksbjkBh8DD24DANWGgC6IZkAEI1EIAArcKAEehEFI2mSIgDCJGJpHUmqcMAgMmg8GU2JknAYbGs-kLMhl8sVysdhPYGAI4ITPr4sronAcTnIfHrdAVBuVqVTwabgpbbY76Jq3ZcfdIA7gfCnmontfZuv1hubsTnZU7i57K7XG51eqIY63cNrGZ4BCc8YJjlJ2NyRf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srDExSqy4JaZUxZvgbagLZzZC1vQsAuD+pEVkAAyB03NBI815sDB0QKnUW6ZPMBYhC5MrbaNKvW8uYUG81kbnW0ZCCsume2VksAAFllsIuFGtkge2tuah20Je0B2ClHceKdqa52rs3f6Xdn9Qh7bByevHO9+Z1hCt0Rj77U8z7XtUn1-76IhsteBxFUHNkFs2XTAAeSW3gIJq3RSI-R7mbgqOkdfaga+bH93kSXeu7L76DhFfc5kPbGo99KfvZpyc2XYyyp9YgPmGohn2dA6aQOoJMAIJqDMxUMdGmB3lnIIh8zt31fE7ABdX8-5AJa-OjXMsC26IXCgDsD7tORWVrEStKaTk-jrmtpspk9RWSAz1fSPbGkhwIQPsTY25F88QtL81P+DNTkRQjhjgg8ZBLGc0ESKEHJCaFc3gcRt9JitmBkxFKrYdaxZfOYiLj9haG9w-OoGU2J77d4gPISfPo+8SB1bl-Lwbe8HHhTt59YWIukmiyHJEPqZBxj+LDu03wmQnfWmB9MErCSJtpHyIPreSRkhi8QGAtGqz+yBxk45jyzX4N6xB1A6R1qf51CeJkCd48jd6sIMJFZIG2ZsCczqq-pqwYD3TXzX6cR6ADjPpPI04PgZjP4z6cAJidxojTqGbYxBwsDYzUESDNib6sHiAb59YwjqgNas7kBeRgYwhAYtpCyejeglJsBr5cG2ab456oEghMTpAPh1AMCxycEET0H1wiRMEsFcASDJBgARwhhAA", # nolint + "app", + mode = "editor" + ), + full_screen = TRUE +) +``` + +

+ +Toggle code + +

+ +
+ +```r library(dplyr) library(tidyr) library(forestplot) +library(blockr.pharmaverseadam) # Function to create adverse event forest plot create_ae_forest_plot <- function(data, usubjid_col, arm_col, aedecod_col, n_events) { @@ -332,7 +343,7 @@ create_ae_forest_plot <- function(data, usubjid_col, arm_col, aedecod_col, n_eve ) } -forest_plot_block <- function(...) { +new_forest_plot_block <- function(...) { new_block( fields = list( usubjid_col = new_select_field( @@ -369,7 +380,7 @@ forest_plot_block <- function(...) { # Register the custom block register_block( - forest_plot_block, + new_forest_plot_block, name = "Adverse Event Forest Plot", description = "Create a forest plot of adverse events comparing two treatment arms", classes = c("adverse_event_plot_block", "plot_block"), @@ -379,16 +390,15 @@ register_block( # Create the stack clinical_trial_stack <- new_stack( - new_dataset_block( - selected = "adae", - package = "pharmaverseadam" - ), + new_adam_block(selected = "adae"), # filter_in_block(), - forest_plot_block() + new_forest_plot_block() ) serve_stack(clinical_trial_stack) ``` +
+ #### 2.2 Demographics Table This demographics table is taken from the `cardinal` package of [FDA Safety Tables and Figures](https://github.com/pharmaverse/cardinal) and demonstrates `gt` and `rtables` outputs starting from the [pharmaverseadam](https://github.com/pharmaverse/pharmaverseadam) `adsl` dataset. diff --git a/vignettes/figures/blockr-stock-demo.png b/vignettes/figures/blockr-stock-demo.png new file mode 100644 index 00000000..c69de0bb Binary files /dev/null and b/vignettes/figures/blockr-stock-demo.png differ