Search code examples
rshinyrgl

texture doesnt map correctly in rglWidget when using rgl package in shiny


I am trying to visualize a sphere with a texture in shiny app using rgl package. However, I've realized that texture isn't mapped correctly in the shiny output compared to RGL Device.

Here is an example:

RGL Device

library(rgl)

spheres3d(
  x = 0,
  y = 0,
  z = 0,
  radius = 1,
  texture = system.file("textures/sunsleep.png", package = "rgl"),
  alpha = 1,
  texmode = "replace",
  textype = "rgb",
  col = "white"
)

rgl plot without using shiny output

Shiny

library(shiny)
library(rgl)

shinyApp(ui = bootstrapPage(
  rglwidgetOutput("widget")
  ),
  server = function(input, output, session) {
    output$widget <- renderRglwidget({
      try(close3d(), silent = TRUE)
      open3d(useNULL = TRUE)
      spheres3d(
        x = 0,
        y = 0,
        z = 0,
        radius = 1,
        texture = system.file("textures/sunsleep.png", package = "rgl"),
        alpha = 1,
        texmode = "replace",
        textype = "rgb",
        col = "white"
      )
      rglwidget()
    })
  }
)

rglWidgetOutput

You can see that they look different, the texture in the shiny output didn't get mapped correctly. How can I fix the texture mapping so it looks exactly like the rgl device version? So far I have tried tweaking the par3d but to no avail.


Solution

  • This is solved in [email protected].

    Install the development version of rgl with:

    remotes::install_github("dmurdoch/rgl")