gargoyle icon indicating copy to clipboard operation
gargoyle copied to clipboard

Bug: arg `session` not passed down from `on()` to `watch()`

Open ilyaZar opened this issue 1 year ago • 0 comments

When working with the tests/testthat/test-funs.R file I realized that the following code part does not work:

library(shiny)
library(gargoyle)

shiny::reactiveConsole(TRUE)
s <- shiny::MockShinySession$new()

init("pif", session = s)
#> [[1]]
#> reactiveVal: [1] "0"
test_for_on_function <- on(
  "pif",
  {
    cat("TEST fails")
  },
  session = s
)
test_for_on_function$.func()
#> Error in session$userData[[name]](): attempt to apply non-function
shiny::reactiveConsole(FALSE)

A more specific error message is goes on:

error message

Warning: Error in session$userData[[name]]: attempt to apply non-function 51: gargoyle::watch [/home/iz/Dropbox/r-pkgs/gargoyle/R/funs.R#107] 50: eval_tidy 49: eventFunc 36: observeEvent(gargoyle::watch("pif")) 35: contextFunc 34: env$runWith 27: ctx$run 26: run 7: flushCallback 6: FUN 5: lapply 4: ctx$executeFlushCallbacks 3: .getReactiveEnvironment()$flush 2: flushReact 1: cb

This is probably because inside the on() function:

on <- function(
  name,
  expr,
  session = getDefaultReactiveDomain()
  ){
  ...
  observeEvent(
      substitute(gargoyle::watch(name)),
  ...
}

the gargoyle::watch(name) does not update the session i.e. it should probably be gargoyle::watch(name, session = session).

May be fixed by #18

ilyaZar avatar Jul 04 '23 11:07 ilyaZar