17
14/11/2012 Durieux Eric / Eusebio Pascal Tcl-Tk : Créer une interface sous R Présentation groupe FltauR

Fltau r interface

  • Upload
    cornec

  • View
    3.211

  • Download
    2

Embed Size (px)

Citation preview

Page 1: Fltau r interface

14/11/2012Durieux Eric / Eusebio Pascal

Tcl-Tk :

Créer une interface sous R

Présentation groupe FltauR

Page 2: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R2

Introduction

Pourquoi créer des interfaces :

Distribuer un ensemble de fonctionnalités développées sous R auprès d’utilisateurs n’ayant aucune notion de programmation en R.

Créer des outils permettant de regrouper l’ensemble des possibilités offerte par R : gestion et manipulation des données – statistique – cartographie …

Promouvoir R au sein de l’Institut

Page 3: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R3

Introduction

Utilisation du langage de script TCL (Tool Command Language) agrémenté de la bibliothèque de création d’interface graphique Tk, combinaison connue sous le nom de Tcl-Tk.

L’ensemble est implémenté sous R dans la librairie « tcltk » présente dans la distribution de base de R

La librairie « tcltk2 » enrichit la précédente librairie mais ne sera pas utilisée dans ce qui suit.

Page 4: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R4

Fenêtres

Messages Box:

library(tcltk)msg<-tkmessageBox(message="Voulez-vous quitter?",icon="question",type="yesnocancel",default="yes")

tclvalue(msg) [1] "no"

Page 5: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R5

Fenêtres

Fenêtre principale:

tt <- tktoplevel()tkwm.geometry(tt,"500x100+0+0")tkwm.title(tt,"ANAlyse Bilocalisée pour les Etudes Locales - ANABEL ")Tkfocus(tt)

Page 6: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R6

Fenêtres

Frames:

Des frames correspondent à des sous-espaces d’une fenêtre principale. On peut donc diviser notre fenêtre en autant de sous-écrans nécessaires.

library(tcltk)tt <- tktoplevel()tkwm.title(tt,"ma fenêtre ")tkwm.geometry(tt,"300x100+0+0")frameOverall <- tkframe(tt)frameUpper <- tkframe(frameOverall,relief="groove",borderwidth=2)tkgrid(tklabel(frameUpper,text="Texte en haut"))frameLower <- tkframe(frameOverall,relief="groove",borderwidth=2)tkgrid(tklabel(frameLower,text="Texte en bas"))

tkgrid(frameUpper)tkgrid(tklabel(frameOverall,text="Texte entre les frames"))tkgrid(frameLower)tkgrid(frameOverall)

Page 7: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R7

Fenêtres

Grid:

tkgrid(frameUpper,frameLower)tkgrid(tklabel(frameOverall,text="Texte entre les frames"))tkgrid(frameOverall)

tkgrid(frameUpper,column=0)tkgrid(tklabel(frameOverall,text="Texte entre les frames"),column=1)tkgrid(frameLower,column=2,row=0)tkgrid(frameOverall)

Page 8: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R8

Fenêtres

Afficher une dataframe:

require(tcltk)tclRequire("Tktable")myRarray <- c("Name","\"James Wettenhall\"","R-Help", "Email","[email protected]","[email protected]")dim(myRarray) <- c(3,2)tclarray <- tclArray() for (i in (0:2))for (j in (0:1))tclarray[[i,j]] <- myRarray[i+1,j+1]

tt<-tktoplevel() table1 <- tkwidget(tt,"table",variable=tclarray,rows=3,cols=2,titlerows=1,selectmode="extended",colwidth=25,background="white")tkpack(table1)

Page 9: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R9

Fenêtres

Afficher une image:

tpropos<<-tktoplevel()tkwm.title(tpropos,"A propos...")tkfocus(tpropos)fpropos<-tkframe(tpropos,relief="groove",borderwidth=2)TxCoRi<<-tkframe(tpropos,relief="groove",borderwidth=2)Txpropos<<-tkframe(tpropos,relief="groove")logo<-read.pnm(paste(d_img,"/logo_pacapsar.pnm",sep=""))img_logo<-tkrplot(fpropos,fun=function() {plot(logo)})CoRit <- tclVar("Copyright LaCrampe Inc.")CoRi<-tklabel(TxCoRi,text=tclvalue(CoRit))fontHeading <- tkfont.create(weight="bold",size=12)fontHeading2 <- tkfont.create(weight="bold",slant="italic",size=8)Txt <- tclVar("Développé par le PSAR \n Analyse Territoriale")Tx<-tklabel(Txpropos,text=tclvalue(Txt),font=fontHeading)fontHeading <- tkfont.create(weight="bold",slant="italic")Tx2<-tklabel(Txpropos,text=paste("Version :",ver_ana),font=fontHeading2)tkgrid.configure(fpropos,sticky="w")tkgrid.configure(CoRi,sticky="w")tkgrid.configure(Txpropos,sticky="e")tkgrid(fpropos,Txpropos)tkgrid(img_logo,Txpropos)tkgrid(TxCoRi)tkgrid(CoRi)tkgrid(Tx)tkgrid(Tx2)

Page 10: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R10

Fenêtres

Afficher un graphique:

Package « tkrplot »

tt <- tktoplevel()bb<-1img <-tkrplot(tt, function() plot(1:20,(1:20)^bb))f<-function(...) {

b <- as.numeric(tclvalue("bb"))if (b != bb) {

bb <<- btkrreplot(img)

}}s <- tkscale(tt, command=f, from=0.05, to=2.00, variable="bb",

showvalue=FALSE, resolution=0.05, orient="horiz")tkpack(img,s)

Page 11: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R11

Menus

Création de menus et sous-menus:

require(tcltk)tt <- tktoplevel()topMenu <- tkmenu(tt)tkconfigure(tt,menu=topMenu)fileMenu <- tkmenu(topMenu,tearoff=FALSE)openRecentMenu <- tkmenu(topMenu,tearoff=FALSE)tkadd(openRecentMenu,"command",label="Fichier 1",

command=function() tkmessageBox(message="C'est quoi Fichier 1?",icon="error"))tkadd(openRecentMenu,"command",label="Fichier 2",

command=function() tkmessageBox(message="C'est quoi Fichier 2",icon="error"))tkadd(fileMenu,"cascade",label="ouvrir fichier",menu=openRecentMenu)tkadd(fileMenu,"command",label="Quit",command=function() tkdestroy(tt))tkadd(topMenu,"cascade",label="File",menu=fileMenu)tkentryconfigure(openRecentMenu,1, state="disabled")tkfocus(tt)

Page 12: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R12

Les widgets

Un large choix de widgets sont disponibles:

Les Edit-Box (tkentry) Les List-Box (tklistbox) Les Checkbox (tkcheckbutton)

Les boutons radio (tkradiobutton)

Page 13: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R13

Exemples

Page 14: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R14

Exemples

Page 15: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R15

Lancement d’une application R / Tcl-Tk

Pour lancer une application R comprenant une interface graphique (ou non..) sans que l’utilisateur n’ait besoin d’ouvrir R au préalable.

Créer un raccourci sur le bureau avec pour cible :

"C:\Program Files\R\R-2.15.1\bin\R.exe" "R_PROFILE=D:\applicarto\Anabel\bin\principal.r" --silent --no-restore --slave --internet2

Page 16: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R16

Biblio

http://http://bioinf.wehi.edu.au/~wettenhall/RTclTkExamples/

http://rstat.ouvaton.org/?article19/creer-des-applications-graphiques-avec-r

Page 17: Fltau r interface

14/11/2012Tcl-Tk : Interface sous R17

Tcl-Tk : Interface sous R

Merci pour votre attention !