【问题标题】:Shiny can not display different "webGLOutput" on different tab panels?Shiny 不能在不同的选项卡面板上显示不同的“webGLOutput”?
【发布时间】:2016-07-31 05:47:04
【问题描述】:

我试图在不同的选项卡面板中显示不同的 3D 图,但我发现 3D 图只显示在第一个选项卡面板中。根据this postplotOutputs 参数outputId 应该是唯一的,并且在我的情况下,ID 在需要闪亮的应用程序中是唯一的。我的应用程序的一些行如下:

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)
  })

})

由于有数百行,我无法将它们全部发布。

根据this post,我更新了shiny的版本,但对我的情况没有影响。

【问题讨论】:

  • 我想知道这是否是 webGL 图的问题。如果将其更改为正常的 R 图,它会起作用吗?
  • 感谢您的回复。你是对的,当我把它改成plotOutput时,它起作用了。那么如何处理这个问题呢?
  • 您应该确保在来自 R-forge 的 rgl 和 rglwidget 的最新版本中看到相同的行为;如果是这样,请整理一份错误报告。它需要是独立的,没有其他人可以运行您问题中的代码。
  • @user2554330 我已经更新了包rglshinyrglwidget,但我仍然遇到同样的问题。
  • 所以简化您的示例,并在适当的位置发布错误报告。

标签: r plot tabs shiny rgl


【解决方案1】:

您似乎在使用shinyRGL。不要用,rgl 有你需要的。这是一个适合我的示例:

ui.R:

library(shiny)

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

服务器.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)
  )

})

顺便说一句,如果您按照要求发布了一个可重现的示例,我们会更快到达这里。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多