New isolate feature (helps with actionButton)

3759 views
Skip to first unread message

Joe Cheng

unread,
Jan 4, 2013, 4:28:20 PM1/4/13
to shiny-...@googlegroups.com
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.)

Arthur Small

unread,
Jan 5, 2013, 12:35:29 PM1/5/13
to shiny-...@googlegroups.com
Joe,

This looks very promising. Thanks so much!

(One small nit: I expect you meant to write install.packages("devtools").)

Cheers,

Arthur

Joe Cheng

unread,
Jan 6, 2013, 8:10:10 PM1/6/13
to shiny-...@googlegroups.com
Yes, install.packages is correct, my mistake!


--
 
 

Andrew Clark

unread,
Jan 8, 2013, 1:59:26 PM1/8/13
to shiny-...@googlegroups.com
I'm having some problems getting to use this

> library("devtools", lib.loc="C:/Users/pssguy/Documents/R/win-library/2.15")
Rtools not installed :(. Please install from http://cran.r-project.org/bin/windows/Rtools/.
> install.packages("Rtools")
Warning in install.packages :
  package ‘Rtools’ is not available (for R version 2.15.2)

Then if I try 
devtools::install_github("shiny", "rstudio")

Installing github repo(s) shiny/master from rstudio
Installing shiny
C:/PROGRA~1/R/R-215~1.2/bin/x64/R --vanilla CMD build  \
  "C:\Users\pssguy\AppData\Local\Temp\RtmpU3W3OB\rstudio-shiny-6639446" --no-manual  \
  --no-resave-data 

* checking for file 'C:\Users\pssguy\AppData\Local\Temp\RtmpU3W3OB\rstudio-shiny-6639446/DESCRIPTION' ... OK
* preparing 'shiny':
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building 'shiny_0.2.4.99.tar.gz'
 ERROR
packaging into .tar.gz failed
Error: Command failed (1)
In addition: Warning message:
running command '"C:/PROGRA~1/R/R-215~1.2/bin/x64/R" --vanilla CMD build "C:\Users\pssguy\AppData\Local\Temp\RtmpU3W3OB\rstudio-shiny-6639446" --no-manual --no-resave-data' had status 1 

Joe Cheng

unread,
Jan 8, 2013, 2:12:07 PM1/8/13
to shiny-...@googlegroups.com
Sorry, forgot to mention that. You need to download and install Rtools from here:

It is necessary for installing any source packages under Windows.


--
 
 

Andrew Clark

unread,
Jan 8, 2013, 2:57:38 PM1/8/13
to shiny-...@googlegroups.com
Thanks - still struggling though after installing it using default 
> library(devtools)
Version of Rtools does not match R version :(. Please reinstall Rtools from http://cran.r-project.org/bin/windows/Rtools/.

sessionInfo()
R version 2.15.2

Rtools website
Rtools216.exeR >2.15.1 to R 2.16.x

Rtools version.txt
Rtools version 2.16.0.1926

restarted computer. still no joy




On Friday, 4 January 2013 13:28:20 UTC-8, Joe Cheng [RStudio] wrote:

Joe Cheng

unread,
Jan 8, 2013, 4:17:00 PM1/8/13
to shiny-...@googlegroups.com
That looks like a devtools bug. Oh well, I've built a binary Windows package for you, it's attached. You should be able to do "R CMD INSTALL shiny_0.2.4.99.zip" from the command line.


--
 
 

shiny_0.2.4.99.zip

Andrew Clark

unread,
Jan 8, 2013, 5:32:23 PM1/8/13
to shiny-...@googlegroups.com
Thanks for taking the trouble Joe
In the command line I have navigated to the same directory as the zip file but when I 
type R CMD INSTALL shiny_0.2.4.99.zip get
'R' is not recognized as an
 internal or external command,
operable program or batch file.
There is a stackflow question on it
but seems quite a bit of effort and may run into the rtools compatibility anyways. I think I will just hold up until
the CRAN update unless there is an obvious solution

Joe Cheng

unread,
Jan 8, 2013, 5:36:42 PM1/8/13
to shiny-...@googlegroups.com
On my machine this works, maybe it's the same for yours:

"C:\Program Files\R\R-2.15.2\bin\R.exe" CMD INSTALL shiny_0.2.4.99.zip


--
 
 

Andrew Clark

unread,
Jan 9, 2013, 3:50:45 PM1/9/13
to shiny-...@googlegroups.com
Tx Once I twigged That I needed to drop down to the x64 subfolder it loaded 
So is that all i need? I remember reading something about the actionButton being in shiny-incubator and I had the
same problem using devtools with that command
devtools::install_github('shiny-incubator' , "rstudio")


On Friday, 4 January 2013 13:28:20 UTC-8, Joe Cheng [RStudio] wrote:

Winston Chang

unread,
Jan 9, 2013, 5:02:08 PM1/9/13
to shiny-...@googlegroups.com
Joe's right, it looks like it is a bug with devtools being too strict about version checking for Rtools. One workaround, if you're using R 2.15.2, is to install Rtools215.exe from the Rtools page (even though the page says that you should install Rtools216.exe).

After you install Rtools215.exe, you should be able to run devtools::install_github() without errors.

-Winston



--
 
 

Glen DePalma

unread,
Jan 10, 2013, 12:43:08 AM1/10/13
to shiny-...@googlegroups.com
This works well for me but I'm experiencing a problem.  I'm using the actionButton in a reactivePrint() function.  I have multiple tabs.  The first time I go to the tab it works as expected, I have to click the button for the function to execute.  However if I move to a different tab and then come back the function executes automatically without pushing the button.  I tried to reset the button value to 0 on the server side during the execution but that does that seem to work.

Joe Cheng

unread,
Jan 10, 2013, 12:45:15 AM1/10/13
to shiny-...@googlegroups.com
Did you make sure to put all other logic besides the action button reference, inside an isolate() call? (Including detecting the active tab)
--
 
 


--
Sent from my phone

Glen DePalma

unread,
Jan 10, 2013, 10:21:20 AM1/10/13
to shiny-...@googlegroups.com
That was the key detecting the active tab within the isolate call.  Thanks!

fred...@tcd.ie

unread,
Jan 23, 2013, 9:25:08 AM1/23/13
to shiny-...@googlegroups.com
Hi, I'm having a very similar problem to Andrew above. My problem is (apparently) not with Rtools (216 installed), as I can load devtools no problem. Yet when I install the git I get the error message below. Any ideas what I should do?

Best, Rolf

> install_github('shiny', username = 'rstudio')

Installing github repo(s) shiny/master from rstudio
Installing shiny.zip from https://api.github.com/repos/rstudio/shiny/zipball/master
Installing shiny
C:/PROGRA~1/R/R-215~1.2/bin/x64/R --vanilla CMD build  \
  "C:\Users\Rolf\AppData\Local\Temp\RtmpeKLAQF\rstudio-shiny-5ace0f1" --no-manual  \
  --no-resave-data

* checking for file 'C:\Users\Rolf\AppData\Local\Temp\RtmpeKLAQF\rstudio-shiny-5ace0f1/DESCRIPTION' ... OK

* preparing 'shiny':
* checking DESCRIPTION meta-information ... OK
Warning: newline within quoted string at plotOutput.Rd:11
Warning: C:/Users/Rolf/AppData/Local/Temp/RtmpCkjfPJ/Rbuildbf448f86ab5/shiny/man/plotOutput.Rd:17: unexpected section header '\value'
Warning: newline within quoted string at plotOutput.Rd:11
Error in parse_Rd("C:/Users/Rolf/AppData/Local/Temp/RtmpCkjfPJ/Rbuildbf448f86ab5/shiny/man/plotOutput.Rd",  :
  Unexpected end of input (in " quoted string opened at plotOutput.Rd:26:24)
Execution halted

Error: Command failed (1)
In addition: Warning message:
running command '"C:/PROGRA~1/R/R-215~1.2/bin/x64/R" --vanilla CMD build "C:\Users\Rolf\AppData\Local\Temp\RtmpeKLAQF\rstudio-shiny-5ace0f1" --no-manual --no-resave-data' had status 1

Winston Chang

unread,
Jan 23, 2013, 10:44:16 AM1/23/13
to shiny-...@googlegroups.com
Hi - please try installing again. There was an error in a documentation file, but it's fixed now.

-Winston


--
 
 

fred...@tcd.ie

unread,
Jan 23, 2013, 11:20:20 AM1/23/13
to shiny-...@googlegroups.com
Works a treat, thanks!
Best, Rolf

Marnik Verschoor

unread,
Mar 19, 2013, 10:29:18 AM3/19/13
to shiny-...@googlegroups.com
Hi, I have a question. I'm quite new to both Shiny and R so please don't take me as a fool if this is a dumb question. I exactly copies your code and put it in server.R. The only thing I changed is the content below the return(isolate). To test if it works, it now says: test = "bla", which is supposed to print if executed succesfully. Yet, everytime I push the actionbutton, nothing happens! Te actionButton does increment so I think that's not the problem.

Is there something really obvious I'm missing here? Maybe loading package or something?

Regards

Op vrijdag 4 januari 2013 22:28:20 UTC+1 schreef Joe Cheng [RStudio] het volgende:

Joe Cheng

unread,
Mar 19, 2013, 3:34:11 PM3/19/13
to shiny-...@googlegroups.com
Maybe I misunderstand, but, why would test = "bla" print anything? Do you mean print("bla")?


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Marnik Verschoor

unread,
Mar 20, 2013, 11:42:13 AM3/20/13
to shiny-...@googlegroups.com
No, I have a output that writes the variable "test". It's standard value is "test". So if the code execute, it should print "bla" instead of "test". Atleast, that's how I see it but I could be wrong. 

Op dinsdag 19 maart 2013 20:34:11 UTC+1 schreef Joe Cheng [RStudio] het volgende:

Timothy Tuti

unread,
May 21, 2013, 12:41:03 PM5/21/13
to shiny-...@googlegroups.com

Winston Chang

unread,
May 21, 2013, 2:39:16 PM5/21/13
to shiny-...@googlegroups.com
Yes, it's probably better in most cases to use actionButton instead of submitButton.


--

vincen...@gmail.com

unread,
May 21, 2013, 5:50:22 PM5/21/13
to shiny-...@googlegroups.com
Given the comment by Winston above why is actionButton is not a part of Shiny while submitButton is?

Winston Chang

unread,
May 21, 2013, 5:55:04 PM5/21/13
to shiny-...@googlegroups.com
actionButton actually is in the development version of Shiny. 

So in the next version of Shiny, you won't need shinyIncubator to use actionButton.

-Winston

vincen...@gmail.com

unread,
May 21, 2013, 6:37:48 PM5/21/13
to shiny-...@googlegroups.com
Excellent!
Reply all
Reply to author
Forward
0 new messages