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.