Rglwidget: cannot replace previous 3D graphics

The example that comes with the package rglwidgetis quite complex; I created a simple example shiny/rglwidgetbelow. The plot looks fine, but every time I switch the checkbox, a new image is added to the browser window.

How can I replace / overwrite the first graph?

options(rgl.useNULL = TRUE)
library(shiny)
library(rglwidget)
library(rgl)

app = shinyApp(
  ui = bootstrapPage(
      checkboxInput("rescale", "Rescale"),
      rglwidgetOutput("rglPlot")
  ),
  server = function(input, output) {
    output$rglPlot <- renderRglwidget({
      try(rgl.close()) # added following @user2554330
      if (input$rescale) aspect3d(1,1,10) else aspect3d(1,1,1)
      # High level function following @user2554330: same effect
      # plot3d(rnorm(100), rnorm(100), rnorm(100,sd = 0.1), 
      #     col = rainbow(1000))
      spheres3d(rnorm(100), rnorm(100), rnorm(100,sd = 0.1), col = "red",
                radius = 0.1)
      axes3d()
      rglwidget()

    })
  })
runApp(app)

Session Information:

R version 3.2.2 (2015-08-14)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

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

other attached packages:
[1] rgl_0.95.1429      rglwidget_0.1.1431 shiny_0.12.2      

loaded via a namespace (and not attached):
 [1] htmlwidgets_0.5.1 R6_2.1.1          rsconnect_0.4.1.9 htmltools_0.2.7  
 [5] tools_3.2.2       yaml_2.1.13       Rcpp_0.12.2       knitr_1.11       
 [9] jsonlite_0.9.19   digest_0.6.8      xtable_1.8-0      Cairo_1.5-9      
[13] httpuv_1.3.3      mime_0.4     
+4
source share
1 answer

It acts just like rgl - when you use low-level commands (spheres 3D, axes3d), they are added to the existing plot. If you want to replace it, the easiest way is to call rgl.close (). next3d () is another possibility, although it is slightly different.

, plot3d persp3d. .

: , , - , . ; - . 0.1.1433 R-forge.

+1

Source: https://habr.com/ru/post/1619090/


All Articles