Fedora-Fr - Communauté francophone Fedora - Linux

Planet de Fedora-Fr : la communauté francophone autour de la distribution Linux Fedora

A propos

Cette page est actualisée toutes les heures.

Cette page est une sélection de blogs autour de Fedora. Fedora-Fr.org décline toute responsabilité au sujet des propos tenus par les auteurs des blogs de ce planet. Leurs propos sont leur entière responsabilité.

Le contenu de ce planet appartient à leurs auteurs respectifs. Merci de consulter leur blogs pour obtenir les licences respectives.

Mot-clefs : pygtk

A simple pygtk R console

Pierre-Yves Chibon


A simple pygtk R console with callback

Une petite interface en pygtk pour R avec affichage des sorties de R dans la fenêtre

English version

Yesterday with the help of Haikel I have made a small interface for R using pygtk. The Window was design with glade, it is a really simple interface: RGUI

User can enter their command in the input field, press the button and the given command will be run in R.

The interface between R and python is made using the rpy2 library.

The tricky part was to actually output the results from R directly in the gtk window as their are generated, in other word, showing the output of the function before the end of the function as some R commande can take a little while.

For this Haikel pointed me to the rpy2 documentation which allows callback from the R terminal. This way one can redirect the output from R into the gtk window. So here is the magic:

def callbackFunction(self, x):
    """ Function which redirect the output from R to the gtk window """
    if self.gtkbuffer is None:
        print x
        self.gtkbuffer.insert(self.gtkbuffer.get_end_iter(), x)
        while gtk.events_pending():

 def runR(self, cmd):
     Function runs in R the given command and set the redirection 
     of the output 
     if len(cmd) > 0:
         self.addToText("> %s" %cmd)
         robjects.r("%s" %cmd )
         # restore default function

The glade file and the full python code are available there:

Results ? See: Rcmd.png