Can you exit from a Shiny app without interrupting R?

1,897 views
Skip to first unread message

richard...@gmail.com

unread,
Jul 12, 2013, 6:15:30 PM7/12/13
to shiny-...@googlegroups.com
Apologies if this has been covered or is trivial, but I can't figure it out:

If you start a Shiny app from within a longer R script, is there a way to exit from the Shiny app and continue with the execution of the calling script?

What I am trying to do is 1) load and reformat a large dataset with an R script, 2) do some processing interactively with Shiny (low-pass filtering, baseline adjustment, peak finding), and 3) run the final computations non-interactively. The official way of ending Shiny (http://rstudio.github.io/shiny/tutorial/#run-and-debug) requires interrupting R by typing Esc or clicking Stop, which also terminates the execution of the calling script.

One way around the problem would be writing the reformatted dataset to a temporary file and pause the calling R script; start Shiny as a separate process, load the temp file, do the interactive processing, and write another temp file; and resume the calling script, read in the second temp file, and finish. That's a bit klutzy, and all the file I/O takes a while.

Another way would be doing everything within the Shiny framework. But I don't want the structure of the entire program to depend on a single R package and I want to be able to interact directly with my data from the R console.

Thanks for any help,

Richard

Jeff Allen

unread,
Jul 13, 2013, 12:27:29 AM7/13/13
to shiny-...@googlegroups.com
If I understand your problem correctly, I think your best bet is to wrap up your workflow in a normal R script, then interject the Shiny app in the middle.

You can do this by taking advantage of the stopApp() command which is available in the latest version of shiny (but perhaps not the version on CRAN). (try `library(devtools); install_github("shiny", "rstudio")`.

stopApp accepts one argument which then gets returned from "runApp()". That would allow you to run some computationally intensive script first, get a result out of runApp(), then continue your script.

Here's an example (that uses knitr to produce an R markdown file) https://gist.github.com/trestletech/5948876 . You could, of course, just use a normal R script instead of knitting together an R markdown doc.

Jeff

richard...@gmail.com

unread,
Jul 13, 2013, 11:17:59 AM7/13/13
to shiny-...@googlegroups.com
Beautiful--that's what I was looking for.

Thank you very much,

Richard
Reply all
Reply to author
Forward
0 new messages