[R-gui] embedding R graphics in Tk widgets

Felix Andrews felix at nfrac.org
Sat Jun 14 03:55:36 CEST 2008

Actually, I would not recommend looking at the playwith code for what
you want to do. The playwith code is quite complicated because it
tries hard to work in many different cases.

For most applications you can use the gWidgets package with
gWidgetsRGtk2, rather than RGtk2 directly. That will make it easier,
with a more R-friendly syntax. Take a look at the gWidgets vignette.
Note that only gWidgetsRGtk2 supports an embedded, interactive device.

If you do decide to use RGtk2 directly, maybe look at
demo(rgtkplot, package="RGtk2")

Since cairoDevice is a proper interactive device, it is resizable, and
you can use locator() or grid.locator() as usual.

Alternatively you could try to use the playwith API to create the
interaction tools you want.

You should be aware that any solution based on RGtk2 will require GTK+
to be installed by your users, whereas TclTk is bundled with R.

On Sat, Jun 14, 2008 at 5:50 AM, Sebastian P. Luque <spluque at gmail.com> wrote:
> Hi,
> Thanks everyone.  To summarize:
> - Embedding of R graphics is trivial with several packages: tkrplot,
>  rpanel, playwith.  The first two do it through behind-the-scenes
>  tcltk, while playwith plays with (couldn't resist it :-) GTK+ and
>  Cairo.
> - Of these, the most versatile approach seems to be that taken by
>  playwith because it allows for resizing of the R graphics, and
>  straightforward access to plot coordinates and locator()-like
>  functionality.
> Looks like I should have a closer look at playwith's code.  Can you
> suggest what parts of the code would be useful in the context of the
> code in my first post?
> Michael -- resizing and/or calling playwith() again as you suggested
> solved the problem, although it didn't seem too small (the plot was
> drawn properly, independently of the size at which it was redrawn).
> However, there some further errors:
> On Fri, 13 Jun 2008 18:24:30 +1000,
> "Felix Andrews" <felix at nfrac.org> wrote:
>> Here is the same using the playwith package:
>> library(playwith)
>> playwith(plot(1:20, (1:20)^cur.time),
>> time.vector=seq(0.05,2,by=0.05))
>> When you click on the plot, the location (in plot coordinates) is
>> shown inside the window.
> It didn't show anything on the window after clicking.  The following
> message was shown in the command-line upon resizing:
> Error in if (playState$is.lattice) { : argument is of length zero

This error is caused by the initial error... does it work if you re-do
the playwith() call?

> Cheers,
> --
> Seb
> _______________________________________________
> R-SIG-GUI mailing list
> R-SIG-GUI at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-gui

Felix Andrews / 安福立
PhD candidate
Integrated Catchment Assessment and Management Centre
The Fenner School of Environment and Society
The Australian National University (Building 48A), ACT 0200
Beijing Bag, Locked Bag 40, Kingston ACT 2604
3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8

More information about the R-SIG-GUI mailing list