A number of you have tried to use the actionButton that's included in shiny-incubator to perform actions, and sometimes those actions needed to read from other reactive inputs. Until now, changes to those other inputs would cause the action to be re-executed, with no clean way to suppress those extra executions.
We just checked in a change to the GitHub repository that should improve things quite a bit. I'm not sure this will be our final solution to this problem, but welcome your feedback.
The change is a new function called "isolate", and it lets you execute code that reads from reactive values/functions, without having their reactivity "infect" the caller.
So a reactive data frame that only recalculates itself when an action button (with the id "recalcButton") is pressed might look like this:
mydata <- reactive(function() {
# Don't do anything until after the first button push.
if (input$recalcButton == 0)
return(NULL)
# Note that just by virtue of checking the value of input$recalcButton,
# we're now going to get called whenever it is pushed.
return(isolate({
# Now do the expensive stuff
foo <- activateInterlock(input$foo)
bar <- connectDynotherm(input$bar)
baz <- bringInfracellsUp(input$baz)
c(foo=foo, bar=bar, baz=baz)
}))
})
So mydata will automatically react to changes in recalcButton (i.e. when it is pushed) but not to changes in the inputs foo, bar, or baz.
How to install
If you'd like to try isolate out for yourself, you can conveniently install the latest build from github using these commands:
install.package("devtools") # if necessary
devtools::install_github("shiny", "rstudio")
(Glimmer users: We generally keep Glimmer synced to the version of Shiny that's on CRAN, so isolate probably won't be available there for at least a couple of weeks. Sorry.)