Leaving graphics created in RScript on the screen while user interaction

I have an R script that queries the database, runs some analysis, displays several diagrams based on the current system date.

I want this script to be run daily at boot time, I thought I could do it quite simply using the shortcut for rscript.exe with the necessary parameters.

This works fine, but the script exits after it is run, which is not very useful for viewing diagrams.

I use XP and win7.

Is there an easy way to save the output from a script on the screen? I tried to enable scanning in the script, but it does not pause.

I know that I could just open rgui and run a single line of code, but the plan is to deploy this to a colleagues computer, which is completely unfamiliar with R.

+7
source share
4 answers

This works for me on Linux:

#!/usr/bin/env Rscript X11() with(mtcars, plot(mpg, hp)) locator(1) 

The user must click on the chart window before it disappears. I assume that it will work on Windows with a call to windows() .

+9
source

Michael may already be working, but here's something showing the plot inside the tkrplot frame. The tkrplot package (on CRAN) uses tcltk extensions for R and is available everywhere.

 # From http://stackoverflow.com/questions/3063165/ # r-building-a-simple-command-line-plotting-tool- # capturing-window-close-events require(tcltk) library(tkrplot) ## function to display plot, called by tkrplot and embedded in a window plotIt <- function(){ plot(x=1:10, y=1:10) } tt <- tktoplevel() ## create top level window event handler done <- tclVar(0) ## variable to wait on ## bind to the window destroy event, set done variable when destroyed tkbind(tt,"<Destroy>",function() tclvalue(done) <- 1) ## Have tkrplot embed the plot window, then realize it with tkgrid tkgrid(tkrplot(tt,plotIt)) tkwait.variable(done) ## wait until done is true ## script continues, or exits, ... once plot is closed 

If you look at the tcltk documentation for R, you will find other examples with Ok buttons to close, etc.

+2
source

What about sys.sleep (1e30)? This should wait long enough.

+2
source

Well, I was going to completely judge all the answers that I saw to this question, because none of them worked on the windows. readline, tkwait.window, Sys.sleep (1e30), while (TRUE), none of them worked.

But I just updated R to v3.1.0, and now tkwait.window (yourmainwindow) works, and (TRUE) {} works, although Sys.sleep (1e30) still doesn't work.

Nothing ... I use tkwait.window because it is tk and is waiting for my window (this is what I want).

Getting, for example, from http://www.sciviews.org/_rgui/tcltk/OKtoplevel.html to work ... (comments are removed for brevity)

 require(tcltk) tt <- tktoplevel() OK.but <- tkbutton(tt, text = "OK", command = function() tkdestroy(tt)) tkgrid(OK.but) tkfocus(tt) tkwait.window(tt) # <-- added this to make the window stay! 
+1
source

All Articles