Forum: help
Monitor Forum | | RE: Strange behaviour of rglwidgets [ Reply ] By: Marco Pescarin Volpato on 2016-01-16 19:41 | [forum:43801] |
|
You are right: I did not realize that I still had rgl package loaded when I updated it. Now all works smoothly. Thank you very much, you did a wonderful work. Marco |
|
| RE: Strange behaviour of rglwidgets [ Reply ] By: Duncan Murdoch on 2016-01-16 18:51 | [forum:42851] |
|
The lazy-load database message probably isn't anything to do with rgl, it likely means you attempted to install it while it was already open. You should have no problem with your original code if you update both rgl and rglwidgets now from R-forge. |
|
| RE: Strange behaviour of rglwidgets [ Reply ] By: Marco Pescarin Volpato on 2016-01-16 09:31 | [forum:42850] |
|
Yes, I've tried it: it works. Here the code: server.R: ----------------------------------------------------------------- options(rgl.useNULL = TRUE) library(shiny) library(rgl) iris<-iris server = function(input, output) { output$sel_x <- renderUI({ a <- unique(colnames(iris[, c(1:4)])) selectInput(inputId = "sel_x", label = "Select x", choices = a, selected = "Sepal.Length") }) output$sel_y <- renderUI({ a <- unique(colnames(iris[, c(1:4)])) selectInput(inputId = "sel_y", label = "Select y", choices = a, selected = "Petal.Length") }) output$sel_z <- renderUI({ a <- unique(colnames(iris[, c(1:4)])) selectInput(inputId = "sel_z", label = "Select z", choices = a, selected = "Sepal.Width") }) iris_reactive<-reactive({ x <- iris[, input$sel_x] y <- iris[, input$sel_y] z <- iris[, input$sel_z] levs <- levels(iris[, "Species"]) colours <- rainbow(length(levs))[as.numeric(iris[, "Species"])] iris_reactive<-data.frame(x, y, z, colours) iris_reactive }) rgl_init <- function(new.device = FALSE, width = 600) { if(new.device | rgl.cur() == 0){ rgl.open() par3d(windowRect = 50+c(0, 0, width, width), mouseMode=c("trackball", "zoom", "fov")) rgl.bg(col="white") } rgl.clear(type = c("shapes", "bboxdeco")) rgl.viewpoint(theta = 15, phi = 20, zoom = 0.7) } webgl_file<-reactive({ iris_reactive<-iris_reactive() rgl_init() rgl.spheres(x = iris_reactive$x, y = iris_reactive$y, z = iris_reactive$z, radius = 0.1, color = iris_reactive$colours) temp_dir <- file.path(tempdir(), "webGL") file_name <- paste(paste(sample(c(0:9, letters, LETTERS), 10, replace = TRUE), collapse = ""), ".html", sep = "") writeWebGL(dir = temp_dir, filename = file.path(temp_dir, file_name), width = 600, height = 600) webgl_file <- list(temp_dir, file_name) }) getPage<-function(webgl_file) { addResourcePath("temp", webgl_file[[1]]) return(tags$iframe(src = paste("temp/", webgl_file[[2]], sep=""), style = "width:100%;", frameborder ="0", id = "iframe", height = "800px")) } output$rglPlot<-renderUI({ webgl_file <- webgl_file() getPage(webgl_file) }) } ----------------------------------------------------------------- ui.R: ----------------------------------------------------------------- options(rgl.useNULL=TRUE) library(shiny) fluidPage( titlePanel("rgl iframe on shiny app"), sidebarPanel( uiOutput("sel_x"), uiOutput("sel_y"), uiOutput("sel_z") ), mainPanel( htmlOutput("rglPlot") ) ) ----------------------------------------------------------------- I downloaded rgl_0.95.1445.tar.gz from http://download.r-forge.r-project.org/src/contrib/?C=M;O=D but when I tried to load it I got: Error in get(method, envir = home) : lazy-load database '/data/R/library/rgl/R/rgl.rdb' is corrupt Inoltre: Warning message: In get(method, envir = home) : internal error -3 in R_decompress1 Errore: package or namespace load failed for ‘rgl’ |
|
| RE: Strange behaviour of rglwidgets [ Reply ] By: Duncan Murdoch on 2016-01-16 09:16 | [forum:42849] |
|
Have you tried your workaround? I don't think it should work. The problem is that you are asking to plot zero spheres, and the Javascript code fails on that. The update I made is to skip plotting if you ask for zero vertices. I'm thinking I may back out that fix, and just fix the Javascript to handle zero vertices. I can imagine a case where you would want to programmatically change the number of vertices, and that would be easier if the zero case was handled like others. |
|
| RE: Strange behaviour of rglwidgets [ Reply ] By: Marco Pescarin Volpato on 2016-01-16 08:37 | [forum:42848] |
|
Thank you very much Duncan. I'll try it as soon as possible. If you are interested a workaround could be to use writeWebGL() to create a temporary file and then to include it in the output web-page using a tags$iframe(), but I think that having it done with rglwidget is better. Have a nice day Marco |
|
| RE: Strange behaviour of rglwidgets [ Reply ] By: Duncan Murdoch on 2016-01-16 01:35 | [forum:42847] |
|
I've now added checks of the input, so that when spheres3d is called with NULL input, no object is created. With that change the Shiny example works, so presumably the code was being called again with valid arguments. This version is only on R-forge currently, but will eventually be sent to CRAN. |
|
| RE: Strange behaviour of rglwidgets [ Reply ] By: Duncan Murdoch on 2016-01-15 20:31 | [forum:42846] |
|
Thanks for the details. Okay, I see the same problem, but I don't think it has to do with rglwidgets. If I set a breakpoint in the server code on line 86 (the first line of spheres3d(iris_reactive$x, iris_reactive$y, iris_reactive$z, col = iris_reactive$colours, radius = 0.1) then I don't see any x, y or z components, just colours. So spheres3d is being passed three NULL values, and it generates a bad spheres object. (It should probably have better error checking and generate nothing, but that wouldn't help you.) Backing up a bit, this is happening because input$sel_x etc are NULL in the definition of iris_reactive. I don't know Shiny well enough to explain how any of this happened, or how to put together an example that doesn't use rglwidget() in order to see if it really is the cause of things, so I don't think I can help. |
|
| RE: Strange behaviour of rglwidgets [ Reply ] By: Marco Pescarin Volpato on 2016-01-15 13:35 | [forum:42844] |
|
Hi Duncan, thank you for your reply. "Doesn't work" means that there's no output. Even the part on sidebar panel seems to be "gone away". From the console of my browser (Firefox 43.0): TypeError: v is undefined rglClass.scr.js:923:5 this.initObj() rglClass.src.js:923 this.initCanvas/<() rglClass.src.js:1832 forEach() self-hosted:211 this.initCanvas() rglClass.src.js:1831 this.initialize() rglClass.src.js:1805 .renderValue() rglWebGL.js:23 overrideMethod/superFuncBound() htmlwidgets.js:73 window.HTMLWidgets.widget/</<() htmlwidgets.js:413 this.onValueChange() shiny.min.js:3 this.onValueChange() shiny.min.js:4 this.receiveOutput() shiny.min.js:3 <anonimo> shiny.min.js:3 this._sendMessagesToHandlers() shiny.min.js:3 this.dispatchMessage() shiny.min.js:3 this.createSocket/c.onmessage() shiny.min.js:3 From rglClass.scr.js from line 922 ... v = obj.vertices; obj.vertexCount = v.length; if (!obj.vertexCount) return; ... Sincerly Marco |
|
| RE: Strange behaviour of rglwidgets [ Reply ] By: Duncan Murdoch on 2016-01-15 12:20 | [forum:42842] |
| "Doesn't work" doesn't tell me what went wrong. | |
| Strange behaviour of rglwidgets [ Reply ] By: Marco Pescarin Volpato on 2016-01-15 10:34 | [forum:42841] |
|
I've noted a strange behaviour of rglwidget in shiny and I'm not able to understand if it's a bug or a fault of mine. Here a sample code: server.R: ----------------------------------------------------------------- options(rgl.useNULL = TRUE) library(shiny) library(rgl) library(rglwidget) iris<-iris server = function(input, output) { output$sel_x <- renderUI({ a <- unique(colnames(iris[, c(1:4)])) selectInput(inputId = "sel_x", label = "Select x", choices = a, selected = "Sepal.Length") }) output$sel_y <- renderUI({ a <- unique(colnames(iris[, c(1:4)])) selectInput(inputId = "sel_y", label = "Select y", choices = a, selected = "Petal.Length") }) output$sel_z <- renderUI({ a <- unique(colnames(iris[, c(1:4)])) selectInput(inputId = "sel_z", label = "Select z", choices = a, selected = "Sepal.Width") }) iris_reactive<-reactive({ x <- iris[, input$sel_x] y <- iris[, input$sel_y] z <- iris[, input$sel_z] levs <- levels(iris[, "Species"]) colours <- rainbow(length(levs))[as.numeric(iris[, "Species"])] iris_reactive<-data.frame(x, y, z, colours) iris_reactive }) rgl_init <- function(new.device = FALSE, width = 600) { if(new.device | rgl.cur() == 0){ rgl.open() par3d(windowRect = 50+c(0, 0, width, width), mouseMode=c("trackball", "zoom", "fov")) rgl.bg(col="white") } rgl.clear(type = c("shapes", "bboxdeco")) rgl.viewpoint(theta = 15, phi = 20, zoom = 0.7) } output$rglPlot <- renderRglwidget({ iris_reactive <- iris_reactive() rgl_init() # This one works spheres3d(iris_reactive$x, iris_reactive$y, 1, col = iris_reactive$colours, radius = 0.1) # This one works # spheres3d(iris_reactive$x, # 1, # iris_reactive$z, # col = iris_reactive$colours, # radius = 0.1) # This one works # spheres3d(1, # iris_reactive$y, # iris_reactive$z, # col = iris_reactive$colours, # radius = 0.1) # This one doesn't work # spheres3d(iris_reactive$x, # iris_reactive$y, # iris_reactive$z, # col = iris_reactive$colours, # radius = 0.1) rglwidget() }) } ----------------------------------------------------------------- ui.R: ----------------------------------------------------------------- options(rgl.useNULL = TRUE) library(shiny) library(rgl) library(rglwidget) fluidPage( titlePanel("rglwidget on shiny app"), sidebarPanel( uiOutput("sel_x"), uiOutput("sel_y"), uiOutput("sel_z") ), mainPanel( rglwidgetOutput("rglPlot") ) ) ----------------------------------------------------------------- My sessioninfo(): > sessionInfo() R version 3.2.3 (2015-12-10) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 14.04.3 LTS locale: [1] LC_CTYPE=it_IT.UTF-8 LC_NUMERIC=C LC_TIME=it_IT.UTF-8 [4] LC_COLLATE=it_IT.UTF-8 LC_MONETARY=it_IT.UTF-8 LC_MESSAGES=it_IT.UTF-8 [7] LC_PAPER=it_IT.UTF-8 LC_NAME=C LC_ADDRESS=C [10] LC_TELEPHONE=C LC_MEASUREMENT=it_IT.UTF-8 LC_IDENTIFICATION=C attached base packages [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_3.2.3 knitr_1.12 and some other data: rgl version: 0.95.1441 rglwidget version: 0.1.1434 R-studio: 0.99.825 Thank you for your attention. Sincerly Marco |
|

