how to avoid " out of memory " in shiny server in a rgl using app

57 Views Asked by At

I am trying to run a rgl shiny app, it works well on my computer but crashes on www.shinyapps.io.

I suspect that the 1GB memory is not enough as the shinyapps.io log tells me Container event from container-8564782: oom (out of memory).

It is 6 triangle3d() relatively complex objects in one rglwidget(). A button create a new translation of these 6 objects and plot it in a new rgl object. I tried to put lit=FALSE in the object to save memory, but it still crashes (not always though). I also suspect that the rgl object is not erased from memory when creating a new one. So I tried rglwidget options (reuse=NA, webGLoptions = list(preserveDrawingBuffer = FALSE)), but deploying for testing is not very efficient...

  • Is there a way to test the app locally with the same 1GB memory?
  • Are there other obvious ways to save memory when using rgl/shiny?

Any pointer welcome!

https://colomb.shinyapps.io/RANDOMstage/ core of the code:

observe({ 
    input$randomise 
    #### Create a random position of each objects using translate3d, plot them using triangle3d.
    amessage = random_obj( objects= objects, position_tot =position_tot, messagesday=messagesday, colorpalette=palette("Okabe-Ito"))
    
    output$rglPlot <- renderRglwidget({
      
      createboden()
      
      view3d (theta = 0, phi = -88, zoom = 0.8, fov = 60)
      outputwidget = rglwidget(reuse=NA, webGLoptions = list(preserveDrawingBuffer = FALSE))
      
      
      outputwidget

    
    })
1

There are 1 best solutions below

0
Julien Colomb On

A major issue was the size of the objects. As objects were STL objects read via readSTL(), I minimised the complexity of the object first using a third party software. (https://3dless.com, objects went from 6MB to 100 kB). It now uses much less memory and runs on the server.