Re: [R] create a gui with a button to change graphic?

From: Gregory Snow <Greg.Snow_at_intermountainmail.org>
Date: Tue 21 Mar 2006 - 05:58:06 EST


Gael,

Try the following to get you started:

library(tkrplot)

y <- rnorm(10000, 10, 2) + 5*sin( (1:10000)/1000 )

tt <- tktoplevel()
left <- tclVar(1)
oldleft <- tclVar(1)
right <- tclVar(100)

f1 <- function(){

	lleft <- as.numeric(tclvalue(left))
	rright <- as.numeric(tclvalue(right))
	x <- seq(lleft,rright,by=1)
	plot(x,y[x], type='b',ylim=range(y))

}

img <- tkrplot(tt, f1)

f2 <- function(...){

	ol <- as.numeric(tclvalue(oldleft))
	tclvalue(oldleft) <- tclvalue(left)
	r <- as.numeric(tclvalue(right))
	tclvalue(right) <- as.character(r + as.numeric(...) - ol)
	tkrreplot(img)

}

f3 <- function(...){

        tkrreplot(img)
}

f4 <- function(...){

	ol <- as.numeric(tclvalue(oldleft))
	tclvalue(left) <- as.character(ol+100)
	tclvalue(oldleft) <- as.character(ol+100)
	r <- as.numeric(tclvalue(right))
	tclvalue(right) <- as.character(r+100)
	tkrreplot(img)

}

s1 <- tkscale(tt, command=f2, from=1, to=length(y),

        variable=left, orient="horiz",label='left') s2 <- tkscale(tt, command=f3, from=1, to=length(y),

        variable=right, orient="horiz",label='right') b1 <- tkbutton(tt, text='->', command=f4)

tkpack(img,s1,s2,b1)

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow@intermountainmail.org
(801) 408-8111
 
 


> -----Original Message-----
> From: r-help-bounces@stat.math.ethz.ch
> [mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of
> Antonio, Fabio Di Narzo
> Sent: Monday, March 20, 2006 6:09 AM
> To: R-help@stat.math.ethz.ch
> Subject: [R] create a gui with a button to change graphic?
>
> See demos in the tcltk package. I remember there was some
> example of interactive graphics, with buttons to change
> graphical parameters. You can start from there...
>
> Antonio, Fabio Di Narzo.
>
> 2006/3/20, Gael de Lannoy <delannoy@dice.ucl.ac.be>:
> >
> > Hello everybody,
> >
> > I am wondering if it is possible to create a gui to plot a
> time series
> > that is very big, it's an EEG signal of 20mins. What I
> would like to
> > do is plot the first 5mins, then have a button on the gui
> that plots
> > the next 5mins when pushed.
> >
> > Is it possible?
> >
> > Thanks in advance !
> >
> > Gael.
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> > http://www.R-project.org/posting-guide.html
> >
> >
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Tue Mar 21 06:22:03 2006

This archive was generated by hypermail 2.1.8 : Tue 21 Mar 2006 - 09:09:18 EST