[R-es] Crear un GUI para R con tcltk

Fernando Macedo fermace en gmail.com
Mie Jul 8 18:10:03 CEST 2015


No opinaré sobre el código puesto que no lo leí. Pero comentar que en 
particular he tenido problemas copiando datos desde excel, en general me 
resulta mejor copiarlos de excel, pegarlos en un editor de texto 
cualquiera y luego copiarlos a R. Por que? Ni idea, como lo he usado 
puntualmente no me he puesto a profundizar en el tema, pero he tenido 
ese problema.

Saludos

DMTV Fernando Macedo
Ayudante del área Mejoramiento Genético
Facultad de Veterinaria - UdelarR - Uruguay
Tel: 26284291
Cel.: 098596947
fermace en gmail.com

El 08/07/15 a las 09:54, Jesús Para Fernández escribió:
> BUenas,
>
> Quiero crear un GUI muy simple, el cual consiste en una ventana, que al abrirse tiene dos botones. El primer boton, copiar, es un boton que ejecutar�a
>
> datos<-read.table("clipboard",header=T,dec=",",sep="\t")
>
> Y el segundo boton muestra todos los data.frames que hay en R
>
> Para ello, estoy usando tcltk, por lo que hago lo siguiente:
>
> require(tcltk)
> tt <- tktoplevel()
> tktitle(tt) <- "Mi primer programa"
>
> # Create a variable to keep track of the state of the dialog window:
> #  If the window is active,                                            done = 0
> #  If the window has been closed using the OK button,                  done = 1
> #  If the window has been closed using the Cancel button or destroyed, done = 2
> done <- tclVar(0)   # tclVar() creates a Tcl variable
>
> # Create two buttons and for each one, set the value of the done variable
> # to an appropriate value
> OK.but <- tkbutton(tt, text = "  OK  ",
>      command = function() tclvalue(done) <- 1)
> Cancel.but <- tkbutton(tt, text = "Cancel",
>      command = function() tclvalue(done) <- 2)
>
> # Place the two buttons on the same row in their assigned window (tt)
> tkgrid(OK.but, Cancel.but)
>
> # Capture the event "Destroy" (e.g. Alt-F4 in Windows) and when this happens,
> # assign 2 to done
> tkbind(tt, "<Destroy>", function() tclvalue(done) <- 2)
>
> tkfocus(tt)         # Place the focus to our tk window
>
> # Do not proceed with the following code until the variable done is non-zero.
> # (but other processes can still run, i.e., the system is not frozen)
> tkwait.variable(done)
>
> # The variable done is now non-zero, so we would like to record its value before
> # destroying the window tt.  If we destroy it first, then done will be set to 2
> # because of our earlier binding, but we want to determine whether the user
> # pressed OK (i.e., see whether done is equal to 1)
>
> doneVal <- as.integer(tclvalue(done))   # Get and coerce content of a Tcl variable
> tkdestroy(tt)
>
> # Test the result
> if (doneVal == 1) {
> datos<-read.table("clipboard",header=T,dec=",",sep="\t")
> }
> if (doneVal == 2) {
> ls()
> }
>
>
> Esto funciona al crearlo en el script de R, pero el poortapapeles no me copia las celdas de excel, sino todo el c�digo anterior.
>
> Podeis echarme una mano??
>
> Gracias!!!
>   		 	   		
> 	[[alternative HTML version deleted]]
>
>
>
> _______________________________________________
> R-help-es mailing list
> R-help-es en r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es


	[[alternative HTML version deleted]]



Más información sobre la lista de distribución R-help-es