0

I know RScript is non-interactive, but I would like to display figures without running into the R interactive console first (the same way as in python and java).

In other words, I am hoping to be able to run a single build command from command prompt or terminal that runs an R script and displays its figures.

Thanks.

IssamLaradji
  • 6,637
  • 8
  • 43
  • 68

1 Answers1

1

If you are familiar with shiny you can build simple shinyApp to display file.png file in browser:

Rscript -e 'png("file.png"); plot(1:10); dev.off(); runApp("display_png_app")'

Good comment by @Ista: you don't need to use shiny, you can simply use browseURL("file.png") command instead runApp.

jangorecki
  • 16,384
  • 4
  • 79
  • 160
  • 3
    You don't need shiny for this, `browseURL` should do the trick, i.e., `Rscript -e 'png("file.png"); plot(1:10); dev.off(); browseURL("file.png");'`. It's worth pointing out that the basic issue here is that graphics devices opened by R will be closed when the script finishes, so we need to open the image in a separate application. Anything that accomplishes that should work. – Ista Jan 25 '15 at 01:23
  • @Ista, you are so awesome! This worked great, and I couldn't find this answer anywhere else. Could you please write this comment as an answer so I can vote it as a correct, elegant answer? – IssamLaradji Jan 25 '15 at 16:08
  • @issamou well my solution is just a small modification to Jan's, I suggest accepting this answer. – Ista Jan 25 '15 at 16:30