R: building a simple command line plotting tool/Capturing window close events
Posted
by user275455
on Stack Overflow
See other posts from Stack Overflow
or by user275455
Published on 2010-06-17T15:34:04Z
Indexed on
2010/06/17
18:03 UTC
Read the original article
Hit count: 205
I am trying to use R within a script that will act as a simple command line plot tool. I.e. user pipes in a csv file and they get a plot. I can get to R fine and get the plot to display through various temp file machinations, but I have hit a roadblock. I cannot figure out how to get R to keep running until the users closes the window.
If I plot and exit, the plot disappears immediately. If I plot and use some kind of infinite loop, the user cannot close the plot; he must exit by using an interrupt which I don't like. I see there is a getGraphicsEvent function, but it claims that the device is not supported (X11). Anyway, it doesn't appear to actually support an onClose event, only onMouseDown.
Any ideas on how to solve this?
edit: Thanks to Dirk for the advice to check out the tk interface. Here is the test code that works:
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) } ##create top level window tt<-tktoplevel() ##variable to wait on like a condition variable, to be set by event handler done <- tclVar(0) ##bind to the window destroy event, set done variable when destroyed tkbind(tt,"",function() tclvalue(done) <- 1) ##Have tkrplot embed the plot window, then realize it with tkgrid tkgrid(tkrplot(tt,plotIt)) ##wait until done is true tkwait.variable(done)
© Stack Overflow or respective owner