Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is.reactive is FALSE for metaReactive variables #103

Open
zsigmas opened this issue Jun 21, 2021 · 2 comments · May be fixed by #120
Open

is.reactive is FALSE for metaReactive variables #103

zsigmas opened this issue Jun 21, 2021 · 2 comments · May be fixed by #120

Comments

@zsigmas
Copy link

zsigmas commented Jun 21, 2021

In some cases it is useful to check if a variable is or is not a reactive. See below an example of an add_1 function that expect either a reactive or a non-reactive.

add_1 <- function(x) {
  reactive ({
    if (is.reactive(x)) {
        x()+1
     } else {
       x+1
     }
    )
  }
}

As expected in a reactive environment:

reactiveConsole(T)
add_1(1)()
[1] 2
add_1(reactive(1))()
[1] 2

But:

add_1(metaReactive({1}))()
Error in x + 1 : non-numeric argument to binary operator

This is quite counterintuitive as my expectation is that add_1 would work in any case.

At the moment I am solving through this two functions:

is.metareactive <- function (x) {
  inherits(x, "shinymeta_reactive")
}

is.anyreactive <- function(x) {
  inherits(x, "reactive") | inherits(x, "shinymeta_reactive")
}
@asadow
Copy link

asadow commented Jun 23, 2023

Also experiencing this.

@jcheng5
Copy link
Member

jcheng5 commented Apr 24, 2024

I would use is.function for this particular case, but, noted. I think it's reasonable for "reactive" to be a class on metaReactive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants