BristolMyersSquibb / blockr

Composable, extensible no-code UI
https://bristolmyerssquibb.github.io/blockr/
GNU General Public License v3.0
36 stars 3 forks source link

Copied/Generated code #442

Open JohnCoene opened 1 month ago

JohnCoene commented 1 month ago

The copied code is not valid as it does not substitute data.

E.g.: run app below, and try to run copied code.

library(shiny)
library(blockr)

new_blk <- function() {
  new_block(
    fields = list(),
    expr = quote({
      data$x <- 1L
      data
    }),
    class = c("blk", "transform_block")
  )
}

stack <- new_stack(
  new_dataset_block("cars"),
  new_blk()
)

serve_stack(stack)
nbenn commented 3 weeks ago

@JohnCoene having a quick look at this, given that (transform) blocks are combined using magrittr pipes, standard syntax applies here. The following should work

new_blk <- function() {
  new_block(
    fields = list(),
    expr = quote({
      .$x <- 1L
      .
    }),
    class = c("blk", "transform_block")
  )
}

stack <- new_stack(
  new_dataset_block("cars"),
  new_blk()
)

serve_stack(stack)

Is this what you are after? Field values are substituted using bquote() syntax, but "data" does not receive special treatment. This is handled by magrittr. For sure this should be better documented!