闪亮 R 内的 scatter3d 椭球参数失败

scatter3d ellipsoid argument inside shiny R failing

进两步,退一步。过去几周我 运行 遇到了一些我无法解决的问题,作为一个有 1 年 R 经验的自强不息的用户,但幸运的是这个网站上有很多很棒的人帮助了我很多!首先,感谢那些人。

现在看来我们已经找到了一种方法,可以将 scatter3d 图放入我正在构建的 Shiny App 中,并让鼠标左键起作用(请参阅我之前的问题)我现在遇到了一个错误,我不明白。

错误是这样说的:第 3 阶的主要次要不是正定的 百思不得其解,发现是在scatter3d的ellipsoid参数里面。

运行宁这工作正常:

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

colors <- rep("grey", 25)  ### dummy palette of all greys
groups <- as.factor(rep(1:25,2)) ### make 5 categories 

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=F)
    scatter3d(x=cars$speed, y=cars$dist, z=cars$time, surface=FALSE, ellipsoid = FALSE, groups = groups, surface.col = colors)
    par3d(mouseMode = "trackball")
    rglwidget()
  })
})   
shinyApp(ui = ui, server = server)

切换到 ellipsoid = TRUE 会出现错误,并且没有任何东西呈现闪亮

运行 仅通过 运行 宁这些行就没有闪亮的图表:

rgl.open(useNULL=F)
    scatter3d(x=cars$speed, y=cars$dist, z=cars$time, surface=FALSE, ellipsoid = TRUE, groups = groups, surface.col = colors)

的工作原理是它在 rgl window 中呈现,但当然仍会打印错误。

将组数更改为小于 14 似乎可以解决问题: 组 <- as.factor(rep(1:13,5)) 组 <- 组[1:50]
没有错误。 组 <- as.factor(rep(1:14,5)) 组 <- 组 [1:50] 给出错误..... 很奇怪。

起初我认为它可能与 scatter3d 的内置颜色 nr 有关,因为最多 8 组,它会自动为事物着色而无需指定 surface.col。一旦你有9组,你需要自己给它一个调色板,但是这个nr 13 cutoff看起来很尴尬....

你的问题是你没有足够的数据。这导致它在没有足够的点时尝试计算一个椭圆体(我想每组至少需要 3 个点)。报错信息明明可以更好一点,但并没有错,是指计算出了什么问题。

我创建了一个参数化的 ncars,它只是对您的原始数据进行了更大的重新采样,所以它看起来应该相似。

这里是:

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

makebigcars <- function(n){
  newspeed <- sample(cars$speed,n,replace=T)
  newdist <- sample(cars$dist,n,replace=T)
  bigcars <- data.frame(speed=newspeed,dist=newdist)
  bigcars$time = bigcars$dist/bigcars$speed
  return(bigcars)
}
ncars <- makebigcars(150)

n <- nrow(ncars)
colors <- rep("grey", n)  ### dummy palette of all greys
groups <- as.factor(rep(1:5,n))[1:n] ## groups

ui <- fluidPage(
  hr("Scatter3d"),

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

server <- (function(input, output) {

  output$plot <- renderRglwidget({
    rgl.open(useNULL=F)
    scatter3d(x=ncars$speed, y=ncars$dist, z=ncars$time, surface=FALSE, 
                ellipsoid = T, groups = groups, surface.col = colors)
    par3d(mouseMode = "trackball")
    rglwidget()
  })
})   
shinyApp(ui = ui, server = server)

这是一个情节: