3

I created some 3D cubes with different colors by using rgl package. My next step is to embed the 3D plot into ggraphics device from the gWidgets package, but I have no idea how to implement it. Is there a way to implement by gWidgets or other package? I have read this similar post, nobody answered the question but a comment@jverzani. Any help? Thank you in advance!

My code:

library(rgl)
library(scatterplot3d)
library(gWidgets)
options(guiToolkit="RGtk2")


df<-data.frame(x=c(1,2,3,4),
               y=c(2,4,6,8),
               z=c(3,6,9,12),
               value=c(33,43,75,21))

clr <- df$value/max(df$value)
f <- colorRamp(c("green", "yellow", "purple", "red"))

## 3D PLOT
for(i in 1:length(df$x)){
  shade3d(translate3d(scale3d(cube3d(col=rgb(f(clr[i])/255),alpha=0.15 ),
                                     10.0, 10.0, 2.5),df$x[i],df$y[i],df$z[i]))
} 

window <- gwindow("TEST", width = 800, height= 600, visible = FALSE)
group <- ggroup(cont = window, expand = TRUE)


loadBtn <- gbutton("display", cont = group)

addHandlerChanged(loadBtn, handler = function(h,...){
  sudwin<-gwindow("3D",visible = TRUE)
  dev <- ggraphics(cont=subwin)
  #### DO NOT KNOW HOW TO DO NEXT...
})
visible(window)<-TRUE
Community
  • 1
  • 1
Just Rookie
  • 209
  • 3
  • 8
  • Hi, use the `shiny` and `shinyrgl` package can solve this problem. – Just Rookie Jul 12 '15 at 03:31
  • Sorry, same comment: to get this done properly would seem torequire something connection between Gtk and openGL that is exposed to the R process. I am unaware of that, though perhaps it is there. It could be worked around by passing around static files and using `gimage`, but I doubt that is what you are after as you would really have to hack in the interactivity. – jverzani Jul 15 '15 at 14:48

0 Answers0