0

I am trying to displaying different 3D plots in different tab panels, but I found that 3D plot only displayed in the first tab panel. According to this post, plotOutputs parameter outputId should be unique, and in my case IDs are unique over the entail shiny app. Some lines of my app are as follow:

ui.R
shinyUI(fluidPage(    
  mainPanel(
    tabsetPanel(
      tabPanel("VWC", webGLOutput("VWC3DPlot")), 
      tabPanel("TEMP", webGLOutput("TEMP3DPlot"))
    )
  )
))


server.R
shinyServer(function(input, output) {

    # set dir;
    dataDir <- "C:/Users/PH/Desktop/data/DATA/"

    # store dataframe of attribute to list;
    dfList <- readIntoDF(dataDir) # readIntoDF() is function that return a list

    # extract dataframe from list
    dfVWC <- dfList$VWC
    dfTEMP <- dfList$TEMP

    # processing of dataframes
    dfVWC <- transformDF(dfVWC)
    dfTEMP <- transformDF(dfTEMP)    

    # prepare grid for kriging;
    grd <- expand.grid(x=seq(from=0, to=600, by=200),
                       y=seq(from=0, to=500, by=200))

    # Kriging;
    dfVWCkrige <- krigingFun(dfVWC, grd)
    dfTEMPKrige <- krigingFun(dfTEMP, grd)

    krigeList <- list("VWCKrige" = dfVWCkrige, "TEMPKrige" = dfTEMPKrige)

    return(krigeList)
  })  # end of dataInput


  ### create cubs;
   output$VWC3DPlot <- renderWebGL({
     createCubes(dataInput()$VWCKrige) # createCubes() is a function that use output of kriging and shinyrgl pkg to create cubes;
   })

  output$TEMP3DPlot <- renderWebGL({
    createCubes(dataInput()$TEMPKrige)
  })

})

Since there are hundreds of lines, I could not to post all of them.

According to this post, I updated the version of shiny, but had no effect on my case.

Community
  • 1
  • 1
just_rookie
  • 873
  • 12
  • 33
  • I wonder if it is an issue with webGL graphs. Does it work if you change it to normal R plots? – Xiongbing Jin Apr 10 '16 at 04:29
  • Thank you for your reply. You are right, when I changed it to `plotOutput`, it worked. So how to handle this issue? – just_rookie Apr 10 '16 at 07:06
  • You should make sure you see the same behaviour in the latest versions of rgl and rglwidget from R-forge; if so, put together a bug report. It needs to be self-contained, nobody else can run the code in your question. – user2554330 Apr 10 '16 at 13:36
  • @user2554330 I have updated package `rgl`, `shiny` and `rglwidget`, but I still got the same problem. – just_rookie Apr 11 '16 at 03:00
  • So simplify your example, and post a bug report in the appropriate place. – user2554330 Apr 12 '16 at 09:24

1 Answers1

3

You appear to be using shinyRGL. Don't use it, rgl has what you need. Here's an example that works for me:

ui.R:

library(shiny)

shinyUI(fluidPage(
  mainPanel(
  tabsetPanel(
    tabPanel("red",
      rglwidgetOutput('thewidget1')),
    tabPanel("green",
      rglwidgetOutput('thewidget2'))
  ))
))

server.R:

library(shiny)
library(rgl)

options(rgl.useNULL = TRUE)
shinyServer(function(input, output, session) {

  x <- rnorm(100)
  y <- 2*rnorm(100)
  z <- 10*rnorm(100)
  open3d()
  plot3d(x, y, z, col = "red")
  scene1 <- scene3d()
  plot3d(z, y, x, col = "green")
  scene2 <- scene3d()
  rgl.close()

  save <- options(rgl.inShiny = TRUE)
  on.exit(options(save))

  output$thewidget1 <- renderRglwidget(
    rglwidget(scene1)
  )

  output$thewidget2 <- renderRglwidget(
    rglwidget(scene2)
  )

})

By the way, we would have got here a lot sooner if you had posted a reproducible example as requested.

user2554330
  • 37,248
  • 4
  • 43
  • 90