Run R interactively from rscript

I am trying to run a brilliant application or interactive .Rmd document from Rscript. However, all I get is a message

Listening to http://127.0.0.1 : ...

I believe that this is due to the fact that R works in interactive mode ( another message about this). How can I write the correct Rscript so that one of the following works?

My script

#!/usr/bin/Rscript ## This library(shiny) runApp(appDir = "../app") ## Or this ## rmarkdown::run("Main.Rmd") 
+6
source share
1 answer

If I understood your question correctly, I was able to achieve this with littler , which I use instead of Rscript for script tasks that revolve around R. I run CentOS 7 and, based on the code in your question, it looks like you're on a Unix-like machine, so installing littler should not be a problem. For minimal reproducibility, I used the standard brilliant application and the brilliant Rmarkdown templates provided by RStudio, saving them as testapp (project / application directory name) and testRMD.rmd respectively. Then I have the following scripts:


testapp.r

 #!/usr/bin/env r shiny::runApp( "~/tmp/delete/testapp", port = 7088, launch.browser = TRUE, host = "127.0.0.1") 

testRMD.r

 #!/usr/bin/env r rmarkdown::run( file = "testRMD.rmd", dir = "~/tmp/delete", shiny_args = list( port = 7088, launch.browser = TRUE, host = "127.0.0.1")) 

Set permissions for these files so that they can be executed -

 [ nathan@nrussell R]$ chmod +x testapp.r testRMD.r 

( chmod +u ... should be enough, but independently ...), and you should be configured to start from your terminal, etc.


 [ nathan@nrussell R]$ ./testapp.r Loading required package: shiny Listening on http://127.0.0.1:7088 

enter image description here

 [ nathan@nrussell R]$ ./testRMD.r Loading required package: shiny Listening on http://127.0.0.1:7088 

enter image description here


There is additional command line output for the Rmd file that I skipped, but I am sure that this can be easily suppressed if necessary. In any case, it seems to be working fine - both the brilliant application and the Rmarkdown application are interactive, as when starting from RStudio, but if you have anything else, please clarify.

+4
source

All Articles