Two working examples, tested on DOS console and IDLE.

#test1.py
#r gui in a separate thread with processevents

from rpy2 import robjects
from rpy2 import rinterface
import thread

def refresh():
    while True:
            rinterface.process_revents()
            time.sleep(0.1)
def plot():
    robjects.r.plot([1,2,3,4],[1,2,3,4])
    refresh()

thread.start_new_thread(plot,())

Run this code with "python -i test1.py".


#test2.py
#r gui and process events all in the main thread

from rpy2 import robjects
from rpy2 import rinterface
import thread

def refresh():
    while True:
            rinterface.process_revents()
            time.sleep(0.1)
def plot():
    robjects.r.plot([1,2,3,4],[1,2,3,4])

plot()
refresh()


If you want to get interactive inputs, you need to make a thread for
input and handle that from a main event loop (with a Queue or
something).

On Thu, Jul 23, 2009 at 4:00 PM, June Kim<junea...@gmail.com> wrote:
> On Thu, Jul 23, 2009 at 2:44 PM, Laurent Gautier<lgaut...@gmail.com> wrote:
>> I am curious to hear whether this is changing much, since the win32-specific
>> fix proposed has been implemented since 2.0.3
>> (http://rpy.sourceforge.net/rpy2/doc/html/changes.html#new-features)
>
> Yes, that works, too.
>
>>
>> You can also see it for yourself here:
>> http://bitbucket.org/lgautier/rpy2/src/6c793f1f1a37/rpy/rinterface/rinterface.c#cl-422
>>
>> The intriguing part is that it works with IDle but not with the (DOS)
>> console (note that your bug report mentioned that at the time it was not
>> working with IDle).
>
> The plot window isn't fully responsive in IDLE, too, with the solution
> of "threading".
>
> As far as I know, R_ProcessEvents should be called from a main thread.
>
> From the R FAQ:
>
> 7.7 The console freezes when my compiled code is running.
> =========================================================
>
> The console, pagers and graphics window all run in the same thread as
> the R engine.  To allow the console etc to respond to Windows events,
> call `R_ProcessEvents()' periodically from your compiled code.  If you
> want output to be updated on the console, call `R_FlushConsole()' and
> then `R_ProcessEvents()'.
>
>
>>
>>
>> L.
>>
>>
>>
>> June Kim wrote:
>>>
>>> Look at how I solved that problem. I have no problem with plot window
>>> currently.
>>>
>>>
>>> http://sourceforge.net/tracker/?func=detail&atid=453021&aid=1944503&group_id=48422
>>>
>>>
>>>
>>> On Wed, Jul 22, 2009 at 12:45 AM, wayne jones<wayne_be...@hotmail.com>
>>> wrote:
>>>>
>>>>  Hi Everyone,
>>>>
>>>> I am trying to run the following simple script to test R graphics using
>>>> rpy2:
>>>>
>>>>
>>>> import rpy2.robjects as robjects
>>>> r = robjects.r
>>>> m = r.matrix(r.rnorm(100), ncol=5)
>>>> pca = r.princomp(m)
>>>> r.plot(pca, main="Eigen values")
>>>>
>>>>
>>>> If I run this script from Idle everything works fine.
>>>>
>>>> However if I run this script line by line in the python terminal window
>>>> then
>>>> the graphics appears but no graph is displayed and when I try to move or
>>>> resize the
>>>> plot it fails and eventually crashes Python.
>>>>
>>>> If I run the script by just double clicking the script file, the graph
>>>> does
>>>> appear this time
>>>> but exhibits strange resizing properties, such as only only being
>>>> patrially
>>>> displayed when the
>>>> window is maximised. Furthermore the graphics menus (such as file->save
>>>> as->jpeg) crash the
>>>> R graphics window.
>>>>
>>>> I am very new to Python and rpy2 but have a good deal of experience with
>>>> R.
>>>>
>>>> Am I missing something? Any help would be appreciated.
>>>>
>>>>
>>>> My setup is:
>>>>
>>>> OS: Windows XP
>>>> Python version: 2.6.2
>>>> R version: 2.9.1
>>>> rpy2: 2.06 (installed from rpy2-2.0.6.win32-py2.6.msi)
>>>>
>>>>
>>>>
>>>> Thanks,
>>>>
>>>> Wayne
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> ________________________________
>>>> Celebrate a decade of Messenger with free winks, emoticons, display pics,
>>>> and more. Get Them Now
>>>>
>>>> ------------------------------------------------------------------------------
>>>>
>>>> _______________________________________________
>>>> rpy-list mailing list
>>>> rpy-list@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/rpy-list
>>>>
>>>>
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> _______________________________________________
>>> rpy-list mailing list
>>> rpy-list@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/rpy-list
>>
>>
>

------------------------------------------------------------------------------
_______________________________________________
rpy-list mailing list
rpy-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rpy-list

Reply via email to