Question

I've been stuck on this issue for a while now and I'm really hoping someone can lend a hand. What I'm trying to do seems relatively simple, but for some reason I just can't get it to work. I'm trying to link the function qmap from the ggmap package with the press of a gbutton from the gwidget2 package so that if I press a button in one window, I can initiate the production of a map in a different window. The closest I've seen to answers on here involve drawing attention to the ggraphic using the visible<- command - this doesn't seem to help. If I just issue the command for the production of the map in the command prompt:

qmap('California')

I get the map no problem, provided I define where the graphical device is properly, but if I try to do this via event handling of the button press, I get nothing... Here is some code to help illustrate my problem.

require(gWidgets2RGtk2)
require(gWidgetsRGtk2)
require(gWidgets2)
require(cairoDevice)
require(ggmap)
require(ggplot2)
require(rgdal)
require(maptools)

w1 <- gwindow()
w2 <- gwindow()

g1 <- ggroup(cont=w1)
g2 <- ggroup(cont=w2)

b1 <- gbutton('Click Me',cont=g2)

gr1 <- ggraphics(cont=g1)

button_press <- addhandlerchanged(b1,  handler=function(h,...) { 
    qmap('California')
    })
Was it helpful?

Solution

As suggested in the comments, you need to:

button_press <- addhandlerchanged(b1,  handler=function(h,...) { 
    print(qmap('California'))
})
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top