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

calling makeReactiveBinding on an object that already has a binding stops reactivity #2065

Open
vnijs opened this issue May 20, 2018 · 1 comment
Milestone

Comments

@vnijs
Copy link
Contributor

vnijs commented May 20, 2018

@jcheng5 FYI I was seeing some strange effects in my app using makeReactiveBinding where the data would stop being reactive at some point. Couldn't consistently reproduce. Then I added checks around all calls to makeReactiveBinding so the binding won't be 'created' if a binding already exists and the problem seemed to go away.

Below in screenshot and code to illustrate the issue. The code below runs in Report > R in radiant.data. Sorry, haven't had time to make an easier to reproduce example.

options(width = 100)

## diamonds is reactive
bindingIsActive(as.symbol("diamonds"), env = r_data)

## making sure we don't have extra variables
diamonds <- select(diamonds, price:z)

## add a variable
diamonds <- mutate(diamonds, extra1 = 42)

## column name is added and .get_data() reactive is updated
colnames(diamonds)
colnames(.get_data())

## recreate the binding
makeReactiveBinding("diamonds", env = r_data)

## add another variable
diamonds <- mutate(diamonds, extra2 = 42)

## diamonds is still listed as reactive but ...
bindingIsActive(as.symbol("diamonds"), env = r_data)

## column name is added BUT .get_data() reactive NOT updated
colnames(diamonds)
colnames(.get_data())

image

vnijs added a commit to radiant-rstats/radiant.data that referenced this issue May 20, 2018
@vnijs vnijs changed the title calling makeReactiveBinding on a object that already has a binding stops reactivity calling makeReactiveBinding on an object that already has a binding stops reactivity May 20, 2018
@vnijs
Copy link
Contributor Author

vnijs commented May 26, 2018

Current work-around:

MRB <- function(x, env = parent.frame(), init = FALSE) {
  if (exists(x, envir = env)) {
    ## if the object exists and has a binding, don't do anything
    if (!bindingIsActive(as.symbol(x), env = env)) {
      shiny::makeReactiveBinding(x, env = env)
    }
  } else if (init) {
    ## initialize a binding (and value) if object doesn't exist yet
    shiny::makeReactiveBinding(x, env = env)
  }
}

vnijs added a commit to radiant-rstats/radiant.data that referenced this issue Jul 17, 2018
@jcheng5 jcheng5 added this to the 1.3 milestone Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants