Skip to content
Prev 383956 / 398502 Next

rgl 0.100.54 using rgl.setMouseCallbacks in pan3d with rglwidget() and shiny server

I am currently attempting to implement rgl and the pan3d function on a 
shiny server but can't get the pan3d function to work. Using the right 
mouse button (2).? Here is a little sample code I was using to try to 
get it to work. Session info below the signature line.


 ?options(rgl.useNULL = TRUE)

 ?library(shiny)
 ?library(rgl)

app = shinyApp(
 ??? ui =
 ??? ? rglwidgetOutput("rglPlot")
 ???? ,
 ? server = function(input, output) {
 ???? ??? output$rglPlot <- renderRglwidget({
 ???? ??? ? options(rgl.useNULL = TRUE)
 ???? ??? ? #rgl::open3d()

 ???? ??? ? # pan3d(2)

 ???? ??? ? ## setup pan function from right mouse button
 ???? ??? ? button <- 2
 ???? ??? ? dev = rgl.cur()
 ???? ??? ? subscene = currentSubscene3d(dev)

 ???? ??? ? start <- list()
 ???? ??? ? begin <- function(x, y) {
 ???? ??? ??? activeSubscene <- rgl::par3d("activeSubscene", dev = dev)
 ???? ??? ??? start$listeners <<- rgl::par3d("listeners", dev = dev, 
subscene = activeSubscene)
 ???? ??? ??? for (sub in start$listeners) {
 ???? ??? ????? init <- rgl::par3d(c("userProjection","viewport"), dev = 
dev, subscene = sub)
 ???? ??? ????? init$pos <- c(x/init$viewport[3], 1 - 
y/init$viewport[4], 0.5)
 ???? ??? ????? start[[as.character(sub)]] <<- init
 ???? ??? ??? }
 ???? ??? ? }

 ???? ??? ? update <- function(x, y) {
 ???? ??? ??? for (sub in start$listeners) {
 ???? ??? ????? init <- start[[as.character(sub)]]
 ???? ??? ????? xlat <- 2*(c(x/init$viewport[3], 1 - y/init$viewport[4], 
0.5) - init$pos)
 ???? ??? ????? mouseMatrix <- rgl::translationMatrix(xlat[1], xlat[2], 
xlat[3])
 ???? ??? ????? rgl::par3d(userProjection = mouseMatrix %*% 
init$userProjection, dev = dev, subscene = sub )
 ???? ??? ??? }
 ???? ??? ? }
 ???? ??? ? rgl::rgl.setMouseCallbacks(button, begin, update, dev = dev, 
subscene = subscene)
 ???? ??? ? #cat("Callbacks set on button", button, "of rgl device", 
dev, "in subscene", subscene, "\n")


 ???? ??? ? spheres3d(rnorm(100), rnorm(100), rnorm(100,sd = 0.1), col = 
"red",
 ? ??? ? radius = 0.1)
 ???? ??? ??? axes3d()

 ??? ??? ??? rglwidget()
 ??? ??? })
 ??? })

runApp(app)