diff --git a/.Rbuildignore b/.Rbuildignore index 25a6254c..14a226b6 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -23,5 +23,6 @@ webpack.prod.js ^\.eslintrc\.js$ ^CODEOWNERS$ ^index\.md$ +^index\.Rmd$ ^wiki ^\.vscode$ diff --git a/README.Rmd b/README.Rmd index d6fa099f..f3bd75a6 100644 --- a/README.Rmd +++ b/README.Rmd @@ -9,8 +9,7 @@ always_allow_html: true knitr::opts_chunk$set( collapse = TRUE, comment = "#>", - fig.path = "man/figures/README-", - out.width = "100%" + fig.path = "man/figures/README-" ) library(blockr) @@ -25,9 +24,13 @@ library(DiagrammeR) [![codecov](https://codecov.io/github/blockr-org/blockr/graph/badge.svg?token=9AO88LK8FJ)](https://codecov.io/github/blockr-org/blockr) -Building blocks for data manipulation and visualization operations. +> {blockr} is Shiny's WordPress (John Coene, 2024) -```{r, echo=FALSE} +## Why blockr? + +`{blockr}` is an R package designed to democratize data analysis by providing a flexible, intuitive, and __code-free__ approach to building data pipelines. It allows users to create __powerful__ data workflows using pre-built __blocks__ that can be easily __connected__, all without writing a single line of code. + +```{r, echo=FALSE, eval=TRUE} mermaid(" flowchart TD subgraph LR workspace[Workspace] @@ -54,7 +57,7 @@ mermaid(" stack2 ---> |... data| stackn end ", - height = "500px" + width = "100%" ) |> htmlwidgets::onRender( "function(el, x) { @@ -64,7 +67,7 @@ mermaid(" ) ``` -Key features: +## Key features 1. **User-Friendly Interface**: Build data pipelines with intuitive interface. 2. **Flexibility**: Easily add, remove, or rearrange blocks in your pipeline. @@ -85,7 +88,7 @@ pak::pak("blockr-org/blockr") Below is a simple case study involving `{blockr}`. We use the palmerpenguins dataset to find out which femal species has the largest flippers. We create 2 custom blocks allowing to create our plot block (see the plot vignette for more details). Note that the `{blockr.ggplot2}` package exposes some ready to use blocks. -```r +```{r, eval=FALSE} library(blockr) library(palmerpenguins) library(ggplot2) @@ -126,7 +129,7 @@ new_geompoint_block <- function(color = character(), shape = character(), ...) { stack <- new_stack( data_block = new_dataset_block("penguins", "palmerpenguins"), - filter_block = new_filter_block("sex", "female"), + filter_block = new_filter_block("sex", "female"), plot_block = new_ggplot_block("flipper_length_mm", "body_mass_g"), layer_block = new_geompoint_block("species", "species") ) diff --git a/README.md b/README.md index 7b4ab433..5c69fcf4 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,21 @@ [![codecov](https://codecov.io/github/blockr-org/blockr/graph/badge.svg?token=9AO88LK8FJ)](https://codecov.io/github/blockr-org/blockr) -Building blocks for data manipulation and visualization operations. +> {blockr} is Shiny’s WordPress (John Coene, 2024) -Key features: +## Why blockr? + +`{blockr}` is an R package designed to democratize data analysis by +providing a flexible, intuitive, and **code-free** approach to building +data pipelines. It allows users to create **powerful** data workflows +using pre-built **blocks** that can be easily **connected**, all without +writing a single line of code. + + #> PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable. + +![](man/figures/README-unnamed-chunk-2-1.png) + +## Key features 1. **User-Friendly Interface**: Build data pipelines with intuitive interface. @@ -82,17 +94,21 @@ new_geompoint_block <- function(color = character(), shape = character(), ...) { stack <- new_stack( data_block = new_dataset_block("penguins", "palmerpenguins"), - filter_block = new_filter_block("sex", "female"), + filter_block = new_filter_block("sex", "female"), plot_block = new_ggplot_block("flipper_length_mm", "body_mass_g"), layer_block = new_geompoint_block("species", "species") ) serve_stack(stack) ``` -``` r -appdir <- system.file("examples", "penguins", package = "blockr") -appshot(appdir, delay = 3) -``` +
+ +Penguins app demo +

+Penguins app demo +

+ +
## Contribute diff --git a/index.Rmd b/index.Rmd new file mode 100644 index 00000000..bad642f5 --- /dev/null +++ b/index.Rmd @@ -0,0 +1,157 @@ +--- +output: github_document +always_allow_html: true +--- + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + comment = "#>", + fig.path = "man/figures/README-" +) + +library(blockr) +library(bslib) +library(DiagrammeR) +``` + + + + +# blockr + + + +[![ci](https://github.com/blockr-org/blockr/actions/workflows/ci.yml/badge.svg)](https://github.com/blockr-org/blockr/actions/workflows/ci.yml) +[![codecov](https://codecov.io/github/blockr-org/blockr/graph/badge.svg?token=9AO88LK8FJ)](https://codecov.io/github/blockr-org/blockr) + + +> {blockr} is Shiny's WordPress (John Coene, 2024) + +## Why blockr? + +`{blockr}` is an R package designed to democratize data analysis by providing a flexible, intuitive, and __code-free__ approach to building data pipelines. It allows users to create __powerful__ data workflows using pre-built __blocks__ that can be easily __connected__, all without writing a single line of code. + +```{r, echo=FALSE} +mermaid(" + flowchart TD + subgraph LR workspace[Workspace] + subgraph stack1[Stack] + direction LR + subgraph input_block[Block 1] + input(Data: dataset, browser, ...) + end + subgraph transform_block[Block 2] + transform(Transform block: filter, select ...) + end + subgraph output_block[Block 3] + output(Result/transform: plot, filter, ...) + end + input_block --> |data| transform_block --> |data| output_block + end + subgraph stack2[Stack 2] + stack1_data[Stack 1 data] --> |data| transform2[Transform] + end + stack1 --> |data| stack2 + subgraph stackn[Stack n] + stacki_data[Stack i data] --> |data| transformn[Transform] --> |data| Visualize + end + stack2 ---> |... data| stackn + end + ", + width = "100%" +) |> + htmlwidgets::onRender( + "function(el, x) { + el.classList.add('text-center') + } + " + ) +``` + +## Key features + +1. **User-Friendly Interface**: Build data pipelines with intuitive interface. +2. **Flexibility**: Easily add, remove, or rearrange blocks in your pipeline. +3. **Extensibility**: Developers can create custom blocks to extend functionality. +4. **Reproducibility**: Pipelines created with `blockr` are easily shareable and reproducible, with exportable code. +5. **Interactivity**: Real-time feedback as you build and modify your pipeline. + +## Installation + +You can install the development version of blockr from [GitHub](https://github.com/) with: + +```r +pak::pak("blockr-org/blockr") +``` + +## Example: palmer penguins case study + +Below is a simple case study involving `{blockr}`. We use the palmerpenguins dataset to find out which +femal species has the largest flippers. We create 2 custom blocks allowing to create our plot block (see the plot vignette for more details). Note that the `{blockr.ggplot2}` package exposes some ready to use blocks. + +
+
+ +
+ + + + + +
+ +```{r, eval=FALSE} +library(blockr) +library(palmerpenguins) +library(ggplot2) + +new_ggplot_block <- function(col_x = character(), col_y = character(), ...) { + + data_cols <- function(data) colnames(data) + + new_block( + fields = list( + x = new_select_field(col_x, data_cols, type = "name"), + y = new_select_field(col_y, data_cols, type = "name") + ), + expr = quote( + ggplot(mapping = aes(x = .(x), y = .(y))) + ), + class = c("ggplot_block", "plot_block"), + ... + ) +} + +new_geompoint_block <- function(color = character(), shape = character(), ...) { + + data_cols <- function(data) colnames(data$data) + + new_block( + fields = list( + color = new_select_field(color, data_cols, type = "name"), + shape = new_select_field(shape, data_cols, type = "name") + ), + expr = quote( + geom_point(aes(color = .(color), shape = .(shape)), size = 2) + ), + class = c("plot_layer_block", "plot_block"), + ... + ) +} + +stack <- new_stack( + data_block = new_dataset_block("penguins", "palmerpenguins"), + filter_block = new_filter_block("sex", "female"), + plot_block = new_ggplot_block("flipper_length_mm", "body_mass_g"), + layer_block = new_geompoint_block("species", "species") +) +serve_stack(stack) +``` + +## Contribute + +Easiest is to run `make`, otherwise: + +1. Install npm dependencies with `packer::npm_install()` +2. Build CSS by running the script in `dev/sass.R` diff --git a/index.md b/index.md index 3fd0c8cd..c3bbec95 100644 --- a/index.md +++ b/index.md @@ -1,5 +1,5 @@ - + # blockr @@ -9,32 +9,30 @@ [![codecov](https://codecov.io/github/blockr-org/blockr/graph/badge.svg?token=9AO88LK8FJ)](https://codecov.io/github/blockr-org/blockr) -Building blocks for data manipulation and visualization operations. +> {blockr} is Shiny’s WordPress (John Coene, 2024) -
-
- -
- - - - - -
+## Why blockr? -`{blockr}` has been built for webR (wasm) and is available for download -with -`webr::install("blockr", repos = "https://blockr-org.github.io/webr-repos")`. +`{blockr}` is an R package designed to democratize data analysis by +providing a flexible, intuitive, and **code-free** approach to building +data pipelines. It allows users to create **powerful** data workflows +using pre-built **blocks** that can be easily **connected**, all without +writing a single line of code. -``` r -library(blockr) -library(blockr.data) +![](man/figures/README-unnamed-chunk-2-1.png) -data_block <- new_dataset_block(selected = "lab", package = "blockr.data") +## Key features -stack <- new_stack(data_block) -serve_stack(stack) -``` +1. **User-Friendly Interface**: Build data pipelines with intuitive + interface. +2. **Flexibility**: Easily add, remove, or rearrange blocks in your + pipeline. +3. **Extensibility**: Developers can create custom blocks to extend + functionality. +4. **Reproducibility**: Pipelines created with `blockr` are easily + shareable and reproducible, with exportable code. +5. **Interactivity**: Real-time feedback as you build and modify your + pipeline. ## Installation @@ -42,8 +40,83 @@ You can install the development version of blockr from [GitHub](https://github.com/) with: ``` r -# install.packages("devtools") -devtools::install_github("blockr-org/blockr") +pak::pak("blockr-org/blockr") +``` + +## Example: palmer penguins case study + +Below is a simple case study involving `{blockr}`. We use the +palmerpenguins dataset to find out which femal species has the largest +flippers. We create 2 custom blocks allowing to create our plot block +(see the plot vignette for more details). Note that the +`{blockr.ggplot2}` package exposes some ready to use blocks. + +
+ +
+ + + +
+ + + + + + + +
+ +``` r +library(blockr) +library(palmerpenguins) +library(ggplot2) + +new_ggplot_block <- function(col_x = character(), col_y = character(), ...) { + + data_cols <- function(data) colnames(data) + + new_block( + fields = list( + x = new_select_field(col_x, data_cols, type = "name"), + y = new_select_field(col_y, data_cols, type = "name") + ), + expr = quote( + ggplot(mapping = aes(x = .(x), y = .(y))) + ), + class = c("ggplot_block", "plot_block"), + ... + ) +} + +new_geompoint_block <- function(color = character(), shape = character(), ...) { + + data_cols <- function(data) colnames(data$data) + + new_block( + fields = list( + color = new_select_field(color, data_cols, type = "name"), + shape = new_select_field(shape, data_cols, type = "name") + ), + expr = quote( + geom_point(aes(color = .(color), shape = .(shape)), size = 2) + ), + class = c("plot_layer_block", "plot_block"), + ... + ) +} + +stack <- new_stack( + data_block = new_dataset_block("penguins", "palmerpenguins"), + filter_block = new_filter_block("sex", "female"), + plot_block = new_ggplot_block("flipper_length_mm", "body_mass_g"), + layer_block = new_geompoint_block("species", "species") +) +serve_stack(stack) ``` ## Contribute diff --git a/man/figures/README-unnamed-chunk-2-1.png b/man/figures/README-unnamed-chunk-2-1.png new file mode 100644 index 00000000..8a47c897 Binary files /dev/null and b/man/figures/README-unnamed-chunk-2-1.png differ diff --git a/vignettes/.gitignore b/vignettes/.gitignore index 097b2416..9e2bd63c 100644 --- a/vignettes/.gitignore +++ b/vignettes/.gitignore @@ -1,2 +1,4 @@ *.html *.R + +/.quarto/ diff --git a/vignettes/blockr_examples.Rmd b/vignettes/blockr_examples.Rmd index 160ebba9..8784c459 100644 --- a/vignettes/blockr_examples.Rmd +++ b/vignettes/blockr_examples.Rmd @@ -1,29 +1,18 @@ --- -title: "blockr: case studies" +title: "Case studies" output: rmarkdown::html_vignette vignette: > - %\VignetteIndexEntry{blockr: case studies} + %\VignetteIndexEntry{Case studies} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r setup, include=FALSE} +library(blockr) library(bslib) knitr::opts_chunk$set(echo = TRUE) ``` -## Why blockr? - -`blockr` is an R package designed to democratize data analysis by providing a flexible, intuitive, and code-free approach to building data pipelines. It allows users to create powerful data workflows using pre-built blocks that can be easily connected, all without writing a single line of code. - -### Key Features - -1. **User-Friendly Interface**: Build data pipelines using a drag-and-drop interface. -2. **Flexibility**: Easily add, remove, or rearrange blocks in your pipeline. -3. **Extensibility**: Developers can create custom blocks to extend functionality. -4. **Reproducibility**: Pipelines created with `blockr` are easily shareable and reproducible, with exportable code. -5. **Interactivity**: Real-time feedback as you build and modify your pipeline. - ## blockr Across Industries The flexibility of `blockr` makes it valuable across various industries. Let's explore how it can be applied in different sectors with detailed examples. Somex examples require to create a new field such as the `new_slider_field` described in the corresponding vignette. @@ -206,20 +195,19 @@ 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") +knitr::include_graphics("figures/blockr-stock-demo.png") ``` ### 2. Pharmaceutical: Clinical Trial Analysis #### 2.1 AE Forest Plot -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. +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. As you may notice, the `new_forest_plot_block` is a quite complex block. Part of the code is isolated in a function `create_ae_forest_plot` so that the main block constructor is more readable. ```{r, eval=TRUE, echo=FALSE} card( create_app_link( "NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAdzgCMAnRRASwgGdSoAbbgCgA6YOtyIEA1gyG4ABAzioi7GQF4ZBQWAAWpUqnaIA9IZFjJAWiIMA5hmstSWgK50MLIodqNz8xe2kyQjp6Bsa+RBgM5tRQ7DAYVtZCAJTJAhBeTKwcXLyaphIMGKhaUAwwUABucAzscFAAJrAB4cpqGkG6+kYmooWWNnYOzq7unvRRrQGdIT3hkdGx8YkpaRDp3CyMZQCefAWSa5vbDHsNqNw7DEdbDLt8pCwNVzcnewBmVnCcF0Skr3dTvs+pJiqVylUanVGrA1ukAMQyABiTggBEeJBkpCI6nkUHIMka1VqcBkcGqZBkn3knBkv1I6QIePIAH0oHAWdTvqQWfSZAAecxU1Ho9wQPhNLiyJzsFwAKyeLOI3FkZRgSqIKsJcAacGIDQ1WogLPJFFI7GSMhA6RkMklUAFQvtMgAPgA+KksbjkBh8DD24DANWGgC6IZkAEI1EIAArcKAEehEFI2mSIgDCJGJpHUmqcMAgMmg8GU2JknAYbGs-kLMhl8sVysdhPYGAI4ITPr4sronAcTnIfHrdAVBuVqVTwabgpbbY76Jq3ZcfdIA7gfCnmontfZuv1hubsTnZU7i57K7XG51eqIY63cNrGZ4BCc8YJjlJ2NyRfzdBqMiId5y3lPVzRkNgyQTLRCXKVNjR7OVQOUGdnXdVNbTqbhQI3XgWUAvgNGHUdDVVcpDVSS00NrW0GhYPs0VIPhKLddCZG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llsIuFGtkge2tuah20Je0B2ClHceKdqa52rs3f6Xdn9Qh7bByevHO9+Z1hCt0Rj77U8z7XtUn1-76IhsteBxFUHNkFs2XTAAeSW3gIJq3RSI-R7mbgqOkdfaga+bH93kSXeu7L76DhFfc5kPbGo99KfvZpyc2XYyyp9YgPmGohn2dA6aQOoJMAIJqDMxUMdGmB3lnIIh8zt31fE7ABdX8-5AJa-OjXMsC26IXCgDsD7tORWVrEStKaTk-jrmtpspk9RWSAz1fSPbGkhwIQPsTY25F88QtL81P+DNTkRQjhjgg8ZBLGc0ESKEHJCaFc3gcRt9JitmBkxFKrYdaxZfOYiLj9haG9w-OoGU2J77d4gPISfPo+8SB1bl-Lwbe8HHhTt59YWIukmiyHJEPqZBxj+LDu03wmQnfWmB9MErCSJtpHyIPreSRkhi8QGAtGqz+yBxk45jyzX4N6xB1A6R1qf51CeJkCd48jd6sIMJFZIG2ZsCczqq-pqwYD3TXzX6cR6ADjPpPI04PgZjP4z6cAJidxojTqGbYxBwsDYzUESDNib6sHiAb59YwjqgNas7kBeRgYwhAYtpCyejeglJsBr5cG2ab456oEghMTpAPh1AMCxycEET0H1wiRMEsFcASDJBgARwhhAA", # nolint - "app", mode = "editor" ), full_screen = TRUE @@ -401,16 +389,15 @@ 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. - +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. As a side note, the below block requires some extra helpers to work properly which you can find [here](https://github.com/blockr-org/blockr.cardinal/blob/72e6e5518d8226d4fdeb599b6e2e31ba03dc7c82/R/methods.R) in the `{blockr.cardinal}` package. -```{r cardinal_tables} +```{r cardinal_tables, eval=FALSE} library(shiny) library(blockr) -library(blockr.falcon) +library(cardinal) library(blockr.pharmaverseadam) -cardinal02_block <- function(...) { +new_cardinal02_block <- function(...) { all_cols <- function(data) colnames(data) fields <- list( @@ -441,7 +428,7 @@ cardinal02_block <- function(...) { ) }) - blockr::new_block( + new_block( expr = expr, fields = fields, ..., @@ -449,8 +436,8 @@ cardinal02_block <- function(...) { ) } -blockr::register_block( - cardinal02_block, +register_block( + new_cardinal02_block, "Cardinal 02", "A Cardinal 02 table", input = "data.frame", @@ -462,26 +449,28 @@ blockr::register_block( # Create the stack rtables_stack <- new_stack( new_adam_block(selected = "adsl"), - cardinal02_block() + new_cardinal02_block() ) serve_stack(rtables_stack) ``` +```{r blockr-cardinal, echo=FALSE, fig.cap='Cardinal demo', fig.align = 'center', out.width='100%'} +knitr::include_graphics("figures/blockr-cardinal-demo.png") +``` ### 3. Environmental Science: Air Quality Analysis and Prediction This example demonstrates a pipeline for analyzing air quality data and predicting future pollution levels using actual data from the [openair](https://github.com/cran/openair) package. -This pipeline imports actual air quality data from the `openair` package and forecasts future pollution levels using an ARIMA model. +This pipeline imports actual air quality data from the `{openair}` package and forecasts future pollution levels using an ARIMA model. -```{r environment} +```{r environment, eval=FALSE} library(blockr) library(openair) library(forecast) - # Custom block for air quality data import -air_quality_block <- function(...) { +new_air_quality_block <- function(...) { new_block( fields = list( site = new_select_field( @@ -515,7 +504,7 @@ air_quality_block <- function(...) { # Custom block for pollution forecasting -pollution_forecast_block <- function(columns = character(), ...) { +new_pollution_forecast_block <- function(columns = character(), ...) { all_cols <- function(data) setdiff(colnames(data), c("date", "site", "source")) new_block( @@ -542,7 +531,7 @@ pollution_forecast_block <- function(columns = character(), ...) { # Register custom blocks register_block( - air_quality_block, + new_air_quality_block, name = "Air Quality Data", description = "Import air quality data", classes = c("air_quality_block", "data_block"), @@ -551,7 +540,7 @@ register_block( ) register_block( - pollution_forecast_block, + new_pollution_forecast_block, name = "Pollution Forecast", description = "Forecast pollution levels", classes = c("pollution_forecast_block", "plot_block"), @@ -561,18 +550,19 @@ register_block( # Create the stack air_quality_stack <- new_stack( - air_quality_block(), - pollution_forecast_block(columns = "no2") + new_air_quality_block(), + new_pollution_forecast_block(columns = "no2") ) serve_stack(air_quality_stack) ``` + ### 4. Marketing: Causal Impact Analysis of Marketing Interventions This example demonstrates how to use [CausalImpact](https://google.github.io/CausalImpact/CausalImpact.html) to analyze the effect of marketing interventions on sales data. -This pipeline generates dummy marketing data with an intervention, then uses CausalImpact to analyze the effect of the intervention on sales. +This pipeline generates dummy marketing data with an intervention, then uses `{CausalImpact}` to analyze the effect of the intervention on sales. This requires to define a new date field as shown below. -```{r date_field, include=FALSE} +```{r date_field} library(shiny) new_date_field <- function(value = Sys.Date(), min = NULL, max = NULL, ...) { blockr::new_field( @@ -591,10 +581,8 @@ date_field <- function(...) { #' @method ui_input date_field #' @export ui_input.date_field <- function(x, id, name) { - ns <- NS(input_ids(x, id)) - shiny::dateInput( - blockr:::input_ids(x, id), + blockr::input_ids(x, id), name, value = blockr::value(x, "value"), min = blockr::value(x, "min"), @@ -613,8 +601,8 @@ validate_field.date_field <- function(x, ...) { ui_update.date_field <- function(x, session, id, name) { updateDateInput( session, - blockr:::input_ids(x, id), - blockr:::get_field_name(x, name), + blockr::input_ids(x, id), + blockr::get_field_name(x, name), value = blockr::value(x), min = blockr::value(x, "min"), max = blockr::value(x, "max") @@ -622,10 +610,7 @@ ui_update.date_field <- function(x, session, id, name) { } ``` - - - -```{r intervention_impact} +```{r intervention_impact, eval=FALSE} library(blockr) library(CausalImpact) library(dplyr) @@ -707,12 +692,12 @@ new_causal_impact_block <- function(columns = character(), ...) { ), expr = quote({ data <- data.frame( + date = data$date, y = data[[.(response_var)]], x = data[[.(covariate_var)]] ) - - pre_period <- c(min(data$date), as.Date(.(pre_period_end))) - post_period <- c(as.Date(.(post_period_start)), max(data$date)) + pre_period <- c(min(as.Date(data$date)), as.Date(.(pre_period_end))) + post_period <- c(as.Date(.(post_period_start)), max(as.Date(data$date))) impact <- CausalImpact(data, pre_period, post_period) plot(impact) @@ -749,6 +734,9 @@ marketing_impact_stack <- new_stack( serve_stack(marketing_impact_stack) ``` +```{r blockr-marketing, echo=FALSE, fig.cap='Marketing demo', fig.align = 'center', out.width='100%'} +knitr::include_graphics("figures/blockr-marketing-demo.png") +``` ### 5. Dynamical systems @@ -758,7 +746,6 @@ In the below example, we implemented the Lorenz attractor and solve it with the card( create_app_link( "NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAdzgCMAnRRASwgGdSoAbbgCgA6YOtyIEA1gyG4ABAzioi7GQF4ZBQWAAWpUqnaIA9IZFjJAWiIMA5hmstSWgK50MLIodqNz8xe2kyQjp6Bsa+RBgM5tRQ7DAYVtZCAJTJAhBeTKwcXLyaphIMdtaooqQATAHhymoaQbr6RiaihZY2dg7Oru6e9FHVAfUhTeGR0bHxiSlpEOncLIxQDACefAWSM-OLK3yoDFAEMFCbC-s760XWJWXlM+kQcNQA+kQAJnBP6zIAPOYyAGZOCAEUjuCB8DCQ5IyEDpdIyGSieQQABePz+gOBoJIMj4pFky1kqCWMHY0NhEARCLqlKpCIAGqoZMSGKTgABGAC6MgAVDJlhzuQBqfnAcrcvkCgDMnNw8LpMgAmkyWWzxbzcQL1X9pZzknLaXSAFpM8wCrkarXC5kk9jAGWWsXcnX2znyhEzBEAXzhtP+LDg3Feyl+iJYnEEhpkUCZD2eECc8AYLAIT39gdefHMAA5DFLZOZ2QAGWTlIv690yOixx5PBNJlNpgNBrPFgsAVhLMmL5YNdIINfjibgydT6Zb5WzsnZ06L5fld1pcc+LXEkbp4+DTM37D7VLgAA89kz2C5OA4nOR1wrYhhXlAuBh-vt4NeFTI3nAACztt-vgFArIlbvssRZMhojJqDOSpMtBJpQRWUbvqQYFqCWwEKqQ-rQNwsFznu-42qyNTqBCfDHLIGBrPqMhUQQqQYR6GGIe+8wRpiTJIhQKKelSLFUpCGAEeo3CxCRdRgJ+K5mIMYD3lw0kSCkC7pD6sw5Ac4jojIy6cJp17LlJ6xAUutZXKURCkIpa6VpiA61JoB6ycsKQmXS7z-FATjcFZxDcImHDgZoywYOyzkYJUYC8TR8rLtYcBEDAihsFZ6zpDM7AjgAbh8ekSHweXiMkYBepyQA", # nolint - "app", mode = "editor" ), full_screen = TRUE diff --git a/vignettes/figures/blockr-cardinal-demo.png b/vignettes/figures/blockr-cardinal-demo.png new file mode 100644 index 00000000..1e014bbd Binary files /dev/null and b/vignettes/figures/blockr-cardinal-demo.png differ diff --git a/vignettes/figures/blockr-marketing-demo.png b/vignettes/figures/blockr-marketing-demo.png new file mode 100644 index 00000000..fee9ad30 Binary files /dev/null and b/vignettes/figures/blockr-marketing-demo.png differ diff --git a/vignettes/new-field.Rmd b/vignettes/new-field.Rmd index 87d021dd..98b12762 100644 --- a/vignettes/new-field.Rmd +++ b/vignettes/new-field.Rmd @@ -112,7 +112,6 @@ We can test our newly created field in a custom block. card( create_app_link( "NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAdzgCMAnRRASwgGdSoAbbgCgA6YOtyIEA1gyG4ABAzioi7GQF4ZBQWAAWpUqnaIA9IZFjJAWiIMA5hmstSWgK50MLIodqNz8xe2kyQjp6Bsa+RBgM5tRQ7DAYVtZCAJTJAhDp3CyMUAwAnnymEgxpGRAQcNQA+uxZACZwDFUAZixw3HUyADzmMs1OEASk7hCCEDITMgBuPE5wqjIQTvAMLBrJuOmTMjBsC0sra3wbW5MwUAAe+8uNRyfjk5wK14frmw8TGF-JMiCnRZJmBVqq12nUxtsZtw5gsoXN3ttduM1EiEWdLgtzhc0RMnqgFnicTIvhgiQRuLFlGohLUWA0mqCOkJTqUAL7pdJOFhVNioJykDC0+ktNodbq9fqDYYkPjYmR02TQeA-P4PdhaNh5ZhCxoASQgfNIEMmAKYrAN-J5dXYstkdPu2yVcCJcPmalNzFdtsCYFdKSJSIWHsQXrlQiR-tOEyxQdExU9szg3vDl0jH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