# NOT RUN {
## simple dnd
lab = glabel("drag me",container=gwindow())
ed = gedit("drop here",container = gwindow())
adddropsource(lab)
adddroptarget(ed)
adddropmotion(ed,handler=function(h,...) print("bombs away"))
## more complicated
## this shows that rows of editable data frame can be dropped.
## by assigning to the changed signal, the graphs can be dynamic.
## THat is, drop a column, then edit it. The graph will update. The key
## is referring to the "value" stored in gd. This refers to the column
## in the editable data frame.
## By using svalue() and id(), the dropped value can also be a
## character string referring to a variable in the workspace.
adf = gdf(mtcars, container = gwindow())
gd = ggraphics(container = gwindow())
plotData = function() {
dropvalue = tag(gd,"value")
theValues = svalue(dropvalue)
theName = id(dropvalue)
hist(theValues, xlab=theName, main="")
}
ids = adddroptarget(gd,targetType="object", handler = function(h,...) {
tag(gd, "value") <- h$dropdata
plotData()
if(is.gdataframecolumn(h$dropdata)) {
view.col = h$dropdata
id = addhandlerchanged(view.col, handler=function(h,...) plotData())
}
})
# }
Run the code above in your browser using DataLab