0

The rgl.snapshot fails when using the patched (install_github("rgl", "trestletech", "js-class")) rgl version with Shiny.

The rgl.snapshot works with rgl >= 0.95.1247. However, due to the known issue of the latest rgl not working with shiny, the output is what's reported initially in this ticket, and the snapshots are just blank / black images.

Here is a reproducible example, taken from shinyRGL github:

server.R

library(shiny)
library(shinyRGL)

#' Define UI for application that plots random 3d points
#' @author Jeff Allen \email{jeff@@trestletech.com}
shinyUI(pageWithSidebar(

    # Application title
    headerPanel("Shiny WebGL!"),
    # Sidebar with a slider input for number of points
    sidebarPanel(
        sliderInput("pts",
        "Number of points:",
        min = 10,
        max = 1000,
        value = 250),
        HTML("<hr />"),
        helpText(HTML("Created using <a href = \"http://github.com/trestletech/shinyRGL\">shinyRGL</a>."))
    ),

    # Show the generated 3d scatterplot
    mainPanel(
        webGLOutput("sctPlot")
    )
))

ui.R

# Must be executed BEFORE rgl is loaded on headless devices.
options(rgl.useNULL=TRUE)

library(shiny)
library(shinyRGL)
library(rgl)

xPts <- runif(1000, 0, 1)
yPts <- runif(1000, 0, 1)
zPts <- runif(1000, 0, 1)

#' Define server logic required to generate and 3d scatterplot
#' @author Jeff Allen \email{jeff@@trestletech.com}
shinyServer(function(input, output) {

# Expression that generates a rgl scene with a number of points corresponding
# to the value currently set in the slider.
    output$sctPlot <- renderWebGL({
        points3d(xPts[1:input$pts],
            yPts[1:input$pts],
            zPts[1:input$pts])
        axes3d()
        rgl.snapshot('./test.png', fmt = 'png')
   })
})

out

Warning in rgl.snapshot("./test.png", fmt = "png") : snapshot failed

sessionInfo

# sessionInfo()
R version 3.2.1 (2015-06-18)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server release 6.4 (Santiago)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] shinyRGL_0.1.1 shiny_0.12.2   rgl_0.93.963 

loaded via a namespace (and not attached):
[1] R6_2.1.1        htmltools_0.2.6 Rcpp_0.12.0     digest_0.6.8   
[5] xtable_1.7-4    httpuv_1.3.3    mime_0.3

Any help is much appreciated.

sredemption
  • 145
  • 1
  • 6

1 Answers1

1

The author of shinyRGL isn't maintaining it any more, as the readme says on his Github repos. However, I've been adding interactivity features to rgl lately. See the vignette "User Interaction in WebGL".

They are still quite rough, and don't make use of Shiny, they insert Javascript directly. I'm currently in the process of rewriting them to be more compatible with Shiny by writing an rgl widget within the htmlwidgets framework. Currently code is in the rglwidget package on R-forge, but I expect it will eventually be merged back into the main rgl package.

Edited to add:

All the code is on the rgl project page on R-forge, https://r-forge.r-project.org/projects/rgl/. To install rglwidget, you should be able to run

install.packages(c("rgl", "rglwidget"), repos="http://R-Forge.R-project.org")

in R (though both packages are under development, so that may sometimes fail).

2nd addition:

In fact, it does currently fail. So you'll have to do it by hand: update rgl from R-forge, then download rglwidget using svn and install from the local copy.

user2554330
  • 37,248
  • 4
  • 43
  • 90
  • I was unable to access the [R-forge package page](https://r-forge.r-project.org/projects/rglwidget/), said "Permission denied. No project was chosen, project does not exist or you can't access it." I did find an [example page](http://rpackages.ianhowson.com/rforge/rglwidget/). – sredemption Sep 08 '15 at 14:59
  • 1
    I've added details above. – user2554330 Sep 09 '15 at 10:44