diff --git a/.lintr b/.lintr index b7d87405..c068a0a5 100644 --- a/.lintr +++ b/.lintr @@ -2,7 +2,8 @@ linters: linters_with_defaults( line_length_linter = line_length_linter(100L), object_name_linter = NULL, # Because we use S3 and end up with is_initialized.field object_usage_linter = NULL, # When code is WIP this is annoying ... - commented_code_linter = NULL # When code is WIP this is annoying ... + commented_code_linter = NULL, # When code is WIP this is annoying ... + cyclocomp_linter = cyclocomp_linter(complexity_limit = 20) ) exclusions: list( "inst/examples/cdisc-plot/example.R", diff --git a/DESCRIPTION b/DESCRIPTION index 7ad4c6b7..a343e749 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: blockr Title: A block-based framework for data manipulation and visualization -Version: 0.0.2.9031 +Version: 0.0.2.9035 Authors@R: c(person(given = "Nicolas", family = "Bennett", @@ -39,7 +39,7 @@ Imports: memuse, haven, rlang, - shinyWidgets + shinyWidgets (>= 0.8.2) Remotes: DivadNojnarg/DiagrammeR, BristolMyersSquibb/blockr.data diff --git a/NEWS.md b/NEWS.md index f6f2e77c..be9747c7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -# blockr 0.0.2.9031 +# blockr 0.0.2.9035 ## Feature - Improved `submit` feature for blocks. Now submit isn't added as a class but as a special block attribute. When you design a block, you can pass the `submit` parameter like so: diff --git a/R/server.R b/R/server.R index 70653199..94d10704 100644 --- a/R/server.R +++ b/R/server.R @@ -21,6 +21,8 @@ generate_server.result_field <- function(x, ...) { res <- get_stack_result( get_workspace_stack(inp) ) + # Handle the join block + if (is.reactive(res)) res <- res() attr(res, "result_field_stack_name") <- inp @@ -44,13 +46,19 @@ generate_server.result_field <- function(x, ...) { updateSelectInput( session, "select-stack", - choices = result_field_stack_opts(session$ns, workspace_stacks()), + choices = result_field_stack_opts(session$ns, names(workspace_stacks())), selected = input[["select-stack"]] ) ) reactive({ - get_result(input[["select-stack"]]) + req(input[["select-stack"]]) + stacks <- workspace_stacks() + blocks <- stacks[[input[["select-stack"]]]]$blocks + all_valid <- lgl_ply(blocks, \(block) { + block$is_valid() + }) + if (all(all_valid) == TRUE) get_result(input[["select-stack"]]) else data.frame() }) }) } @@ -159,6 +167,7 @@ generate_server_block <- function( obs$update_blk <- observeEvent(c(r_values(), in_dat(), is_prev_valid()), { # 1. upd blk, + is_valid$block <- FALSE b <- update_blk( b = blk(), value = r_values(), @@ -210,7 +219,7 @@ generate_server_block <- function( out_dat <- if (attr(x, "submit") > -1) { eventReactive(input$submit, { - req(is_valid$block) + if (!is_valid$block) return(data.frame()) if (is.null(in_dat())) { evaluate_block(blk()) } else { @@ -223,10 +232,13 @@ generate_server_block <- function( ) } else { reactive({ - req(is_valid$block) + if (!is_valid$block) return(data.frame()) if (is.null(in_dat()) && !inherits(x, "transform_block")) { evaluate_block(blk()) } else { + if (inherits(in_dat(), "data.frame") && nrow(in_dat()) == 0) { + return(data.frame()) + } evaluate_block(blk(), data = in_dat()) } }) @@ -396,10 +408,15 @@ generate_server.stack <- function(x, id = NULL, new_block = NULL, # Any block change: data or input should be sent # up to the stack so we can properly serialise. observeEvent( - c( - get_block_vals(vals$blocks), - get_last_block_data(vals$blocks)() - ), + { + lapply(vals$blocks, \(block) { + req(block) + }) + c( + get_block_vals(vals$blocks), + get_last_block_data(vals$blocks)() + ) + }, { vals$stack <- set_stack_blocks( vals$stack, @@ -702,9 +719,17 @@ generate_server.workspace <- function(x, id, ...) { }) attr(x, "reactive_stack_directory") <- reactive({ - names(vals$stacks) + vals$stacks }) |> bindEvent( - chr_ply(lapply(vals$stacks, `[[`, "stack"), attr, "title") + c( + chr_ply(lapply(vals$stacks, `[[`, "stack"), attr, "title"), + lapply(vals$stack, \(stack) { + lgl_ply(stack$blocks, \(block) { + block$is_valid() + block$block + }) + }) + ) ) # Serialize diff --git a/_pkgdown.yml b/_pkgdown.yml index 978229fb..4cd3a6d4 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -206,6 +206,6 @@ reference: news: releases: - - text: "blockr 0.0.2.9031" + - text: "blockr 0.0.2.9035" - text: "blockr 0.0.2" - text: "blockr 0.0.1.9000" diff --git a/tests/testthat/_snaps/block/block-app-001_.new.png b/tests/testthat/_snaps/block/block-app-001_.new.png index 63396905..ce22786d 100644 Binary files a/tests/testthat/_snaps/block/block-app-001_.new.png and b/tests/testthat/_snaps/block/block-app-001_.new.png differ diff --git a/tests/testthat/_snaps/block/block-app-001_.png b/tests/testthat/_snaps/block/block-app-001_.png index 634c6e13..321c6524 100644 Binary files a/tests/testthat/_snaps/block/block-app-001_.png and b/tests/testthat/_snaps/block/block-app-001_.png differ diff --git a/tests/testthat/_snaps/block/block-app-002_.new.png b/tests/testthat/_snaps/block/block-app-002_.new.png deleted file mode 100644 index 88e2cad6..00000000 Binary files a/tests/testthat/_snaps/block/block-app-002_.new.png and /dev/null differ diff --git a/tests/testthat/_snaps/block/block-app-002_.png b/tests/testthat/_snaps/block/block-app-002_.png index 826b2d2b..88e2cad6 100644 Binary files a/tests/testthat/_snaps/block/block-app-002_.png and b/tests/testthat/_snaps/block/block-app-002_.png differ diff --git a/tests/testthat/_snaps/block/block-app-003_.new.png b/tests/testthat/_snaps/block/block-app-003_.new.png deleted file mode 100644 index b4d056ed..00000000 Binary files a/tests/testthat/_snaps/block/block-app-003_.new.png and /dev/null differ diff --git a/tests/testthat/_snaps/block/block-app-003_.png b/tests/testthat/_snaps/block/block-app-003_.png index f598c006..b4d056ed 100644 Binary files a/tests/testthat/_snaps/block/block-app-003_.png and b/tests/testthat/_snaps/block/block-app-003_.png differ diff --git a/tests/testthat/_snaps/block/block-app-004_.new.png b/tests/testthat/_snaps/block/block-app-004_.new.png deleted file mode 100644 index 7cf37837..00000000 Binary files a/tests/testthat/_snaps/block/block-app-004_.new.png and /dev/null differ diff --git a/tests/testthat/_snaps/block/block-app-004_.png b/tests/testthat/_snaps/block/block-app-004_.png index acbb1285..7cf37837 100644 Binary files a/tests/testthat/_snaps/block/block-app-004_.png and b/tests/testthat/_snaps/block/block-app-004_.png differ diff --git a/tests/testthat/_snaps/block/block-app-005_.new.png b/tests/testthat/_snaps/block/block-app-005_.new.png deleted file mode 100644 index f5ae933a..00000000 Binary files a/tests/testthat/_snaps/block/block-app-005_.new.png and /dev/null differ diff --git a/tests/testthat/_snaps/block/block-app-005_.png b/tests/testthat/_snaps/block/block-app-005_.png index a755f04d..30bec99f 100644 Binary files a/tests/testthat/_snaps/block/block-app-005_.png and b/tests/testthat/_snaps/block/block-app-005_.png differ diff --git a/tests/testthat/_snaps/result/result-app-001_.new.png b/tests/testthat/_snaps/result/result-app-001_.new.png index e9b0d0c5..038fed30 100644 Binary files a/tests/testthat/_snaps/result/result-app-001_.new.png and b/tests/testthat/_snaps/result/result-app-001_.new.png differ diff --git a/tests/testthat/_snaps/stack/stack-app-001_.png b/tests/testthat/_snaps/stack/stack-app-001_.png index f5ae933a..30bec99f 100644 Binary files a/tests/testthat/_snaps/stack/stack-app-001_.png and b/tests/testthat/_snaps/stack/stack-app-001_.png differ diff --git a/tests/testthat/_snaps/stack/stack-app-002_.new.png b/tests/testthat/_snaps/stack/stack-app-002_.new.png deleted file mode 100644 index 6b451e7f..00000000 Binary files a/tests/testthat/_snaps/stack/stack-app-002_.new.png and /dev/null differ diff --git a/tests/testthat/_snaps/stack/stack-app-002_.png b/tests/testthat/_snaps/stack/stack-app-002_.png index d28a2e6a..78c2c4ab 100644 Binary files a/tests/testthat/_snaps/stack/stack-app-002_.png and b/tests/testthat/_snaps/stack/stack-app-002_.png differ diff --git a/tests/testthat/_snaps/stack/stack-app-003.json b/tests/testthat/_snaps/stack/stack-app-003.json index 8819cc6c..af565436 100644 --- a/tests/testthat/_snaps/stack/stack-app-003.json +++ b/tests/testthat/_snaps/stack/stack-app-003.json @@ -39,8 +39,8 @@ ], "choices": [ - "function (data) ", - "colnames(data)" + "structure(function (data) ", + "colnames(data), result = c(\"Time\", \"demand\"))" ], "multiple": true } diff --git a/tests/testthat/_snaps/stack/stack-app-003_.new.png b/tests/testthat/_snaps/stack/stack-app-003_.new.png deleted file mode 100644 index b6a99d73..00000000 Binary files a/tests/testthat/_snaps/stack/stack-app-003_.new.png and /dev/null differ diff --git a/tests/testthat/_snaps/stack/stack-app-003_.png b/tests/testthat/_snaps/stack/stack-app-003_.png index 173fce55..25a43b93 100644 Binary files a/tests/testthat/_snaps/stack/stack-app-003_.png and b/tests/testthat/_snaps/stack/stack-app-003_.png differ diff --git a/tests/testthat/_snaps/stack/stack-app-004.json b/tests/testthat/_snaps/stack/stack-app-004.json index 8819cc6c..af565436 100644 --- a/tests/testthat/_snaps/stack/stack-app-004.json +++ b/tests/testthat/_snaps/stack/stack-app-004.json @@ -39,8 +39,8 @@ ], "choices": [ - "function (data) ", - "colnames(data)" + "structure(function (data) ", + "colnames(data), result = c(\"Time\", \"demand\"))" ], "multiple": true } diff --git a/tests/testthat/_snaps/stack/stack-app-004_.new.png b/tests/testthat/_snaps/stack/stack-app-004_.new.png deleted file mode 100644 index 3cd83561..00000000 Binary files a/tests/testthat/_snaps/stack/stack-app-004_.new.png and /dev/null differ diff --git a/tests/testthat/_snaps/stack/stack-app-004_.png b/tests/testthat/_snaps/stack/stack-app-004_.png index df7d30a3..bbc7d98b 100644 Binary files a/tests/testthat/_snaps/stack/stack-app-004_.png and b/tests/testthat/_snaps/stack/stack-app-004_.png differ diff --git a/tests/testthat/_snaps/stack/stack-app-005.json b/tests/testthat/_snaps/stack/stack-app-005.json index 7e62e68f..a70b29a8 100644 --- a/tests/testthat/_snaps/stack/stack-app-005.json +++ b/tests/testthat/_snaps/stack/stack-app-005.json @@ -39,8 +39,8 @@ ], "choices": [ - "function (data) ", - "colnames(data)" + "structure(function (data) ", + "colnames(data), result = c(\"Time\", \"demand\"))" ], "multiple": true } diff --git a/tests/testthat/_snaps/stack/stack-app-005_.new.png b/tests/testthat/_snaps/stack/stack-app-005_.new.png deleted file mode 100644 index e4785146..00000000 Binary files a/tests/testthat/_snaps/stack/stack-app-005_.new.png and /dev/null differ diff --git a/tests/testthat/_snaps/stack/stack-app-005_.png b/tests/testthat/_snaps/stack/stack-app-005_.png index 4f1e88e2..37be1972 100644 Binary files a/tests/testthat/_snaps/stack/stack-app-005_.png and b/tests/testthat/_snaps/stack/stack-app-005_.png differ diff --git a/tests/testthat/_snaps/stack/stack-app-006.json b/tests/testthat/_snaps/stack/stack-app-006.json index 3952aeb2..2cf11793 100644 --- a/tests/testthat/_snaps/stack/stack-app-006.json +++ b/tests/testthat/_snaps/stack/stack-app-006.json @@ -39,8 +39,8 @@ ], "choices": [ - "function (data) ", - "colnames(data)" + "structure(function (data) ", + "colnames(data), result = c(\"Time\", \"demand\"))" ], "multiple": true } diff --git a/tests/testthat/_snaps/stack/stack-app-006_.new.png b/tests/testthat/_snaps/stack/stack-app-006_.new.png deleted file mode 100644 index f4b7011e..00000000 Binary files a/tests/testthat/_snaps/stack/stack-app-006_.new.png and /dev/null differ diff --git a/tests/testthat/_snaps/stack/stack-app-006_.png b/tests/testthat/_snaps/stack/stack-app-006_.png index 0c362ef4..74259bf0 100644 Binary files a/tests/testthat/_snaps/stack/stack-app-006_.png and b/tests/testthat/_snaps/stack/stack-app-006_.png differ diff --git a/tests/testthat/_snaps/stack/stack-app-007.json b/tests/testthat/_snaps/stack/stack-app-007.json index 5d5eae82..2e06ed50 100644 --- a/tests/testthat/_snaps/stack/stack-app-007.json +++ b/tests/testthat/_snaps/stack/stack-app-007.json @@ -39,8 +39,8 @@ ], "choices": [ - "function (data) ", - "colnames(data)" + "structure(function (data) ", + "colnames(data), result = c(\"Time\", \"demand\"))" ], "multiple": true } diff --git a/tests/testthat/_snaps/stack/stack-app-007_.png b/tests/testthat/_snaps/stack/stack-app-007_.png index 9e958ce7..475b2e6e 100644 Binary files a/tests/testthat/_snaps/stack/stack-app-007_.png and b/tests/testthat/_snaps/stack/stack-app-007_.png differ diff --git a/tests/testthat/_snaps/workspace/restore-workspace-app-001_.new.png b/tests/testthat/_snaps/workspace/restore-workspace-app-001_.new.png index 83cfc7a3..e8b4f71f 100644 Binary files a/tests/testthat/_snaps/workspace/restore-workspace-app-001_.new.png and b/tests/testthat/_snaps/workspace/restore-workspace-app-001_.new.png differ diff --git a/tests/testthat/_snaps/workspace/workspace-app-001_.new.png b/tests/testthat/_snaps/workspace/workspace-app-001_.new.png index ba1f0729..30df0c07 100644 Binary files a/tests/testthat/_snaps/workspace/workspace-app-001_.new.png and b/tests/testthat/_snaps/workspace/workspace-app-001_.new.png differ diff --git a/tests/testthat/_snaps/workspace/workspace-app-002_.new.png b/tests/testthat/_snaps/workspace/workspace-app-002_.new.png index 491126e9..df0a8915 100644 Binary files a/tests/testthat/_snaps/workspace/workspace-app-002_.new.png and b/tests/testthat/_snaps/workspace/workspace-app-002_.new.png differ diff --git a/tests/testthat/_snaps/workspace/workspace-app-003_.new.png b/tests/testthat/_snaps/workspace/workspace-app-003_.new.png index 6b69d050..95f66b3c 100644 Binary files a/tests/testthat/_snaps/workspace/workspace-app-003_.new.png and b/tests/testthat/_snaps/workspace/workspace-app-003_.new.png differ diff --git a/tests/testthat/_snaps/workspace/workspace-app-004_.new.png b/tests/testthat/_snaps/workspace/workspace-app-004_.new.png index ba1f0729..30df0c07 100644 Binary files a/tests/testthat/_snaps/workspace/workspace-app-004_.new.png and b/tests/testthat/_snaps/workspace/workspace-app-004_.new.png differ diff --git a/tests/testthat/test-validate-block.R b/tests/testthat/test-validate-block.R index 8513dc8b..1a8ab128 100644 --- a/tests/testthat/test-validate-block.R +++ b/tests/testthat/test-validate-block.R @@ -14,7 +14,6 @@ testServer(module_server_test, { # Invalidate session$setInputs("columns" = "") session$flushReact() - expect_error(out_dat()) expect_false(is_valid$block) expect_identical(is_valid$message, "selected value(s) not among provided choices") expect_identical(is_valid$fields, "columns")