How to render scatter3d inside shiny page instead of popup

I am looking at implementing 3D interactive plots in my brilliant application and so far I have used plot. However, the plot has one major drawback: it is very slow when rendering. I've done checks and the whole creation of the updated outplot $ plot <- renderPlotly ({.....}) and plotlyOutput ("plot") takes less than 0.5 seconds despite the large dataset. This is a problem of knowledge for many years, but it still seems relevant.

Hence, I am looking to use a package called car, also because it has many options, some of which I especially want that are not available in other packages. The car pack information is here: http://www.sthda.com/english/wiki/amazing-interactive-3d-scatter-plots-r-software-and-data-visualization The problem is that it appears in a separate popup window, not inside a shiny app, and I want it to be inside it, or even better, add a button that will allow the user to have it as a popup, but only when asked. However, I can't figure out how to hush up a bugger on a real shiny page.

Here is my minimal example with a single text element and graphical code that (in my case) continues to appear in a separate window and not in the application.

install.packages(c("rgl", "car", "shiny"))

library("rgl")
library("car")
library(shiny)

cars$time <- cars$dist/cars$speed


ui <- fluidPage(
  hr("how do we get the plot inside this app window rather than in a popup?"),

  plotOutput("plot",  width = 800, height = 600)
  )


server <- (function(input, output) {


  output$plot <- renderPlot({
    scatter3d(x=cars$speed, y=cars$dist, z=cars$time, surface=FALSE, ellipsoid = TRUE)
    })
})


shinyApp(ui = ui, server = server)

      

There is also this package, scatterplot3d, but it is not interactive http://www.sthda.com/english/wiki/scatterplot3d-3d-graphics-r-software-and-data-visualization

And there are some RGL packages, but they have the same problem (separate window) and do not offer the options that I am looking for.

+3


source to share


1 answer


You need to use rglwidget

which takes the latest rgl plot and fits into htmlwidget

. It used to be in a separate package, but it has recently been integrated into `rgl.

Here's the code for that:

library(rgl)
library(car)
library(shiny)

cars$time <- cars$dist/cars$speed

ui <- fluidPage(
  hr("how do we get the plot inside this app window rather than in a popup?"),

  rglwidgetOutput("plot",  width = 800, height = 600)
)

server <- (function(input, output) {

  output$plot <- renderRglwidget({
    rgl.open(useNULL=T)
    scatter3d(x=cars$speed, y=cars$dist, z=cars$time, surface=FALSE, ellipsoid = TRUE)
    rglwidget()
  })
})   
shinyApp(ui = ui, server = server)

      



While holding this:

enter image description here

+4


source







All Articles