0

我正在尝试创建一个快速应用程序,让用户选择 3 个变量并使用 scatter3D 重新生成 3D 散点图。使用闪亮时我一直遇到这个错误,我看不到纠正它。

错误:并非所有参数都具有相同的长度

如果替换,我的代码也可以工作:

x = paste("df.output$",input$test,sep=""),
y = paste("df.output$",input$test2,sep=""),
z = paste("df.output$",input$test3,sep=""),

x = df.output$age_scaled
y = df.output$freq_scaled
z = df.output$bonus_scaled

我的 ui 函数看起来像这样

ui <- fluidPage(
  titlePanel("3 Dimensional Cluster Analysis"),
  sidebarLayout( 
  sidebarPanel(
  selectInput("test", "X-Axis", choices=colnames(df.output) , 
  selected=colnames(df.output[1]), width = NULL, size = NULL),
    selectInput("test2", "Y-Axis", choices=colnames(df.output), 
  selected=colnames(df.output[2]), width = NULL, size = NULL),
    selectInput("test3", "Z-Axis", choices=colnames(df.output), 
  selected=colnames(df.output[3]), width = NULL, size = NULL)),

   mainPanel(
    rglwidgetOutput("plot",  width = 1000, height = 500)
      )
    ))

服务器功能看起来像这样

library(rgl)

server <- (function(input, output) 
{
  # reactive({
  #   a <- paste("df.output$",test$input,sep="")
  # })
  output$plot <- renderRglwidget(
    {
      rgl.open(useNULL=T)
      scatter3d(
        x = paste("df.output$",input$test,sep=""),
        y = paste("df.output$",input$test2,sep=""),
        z = paste("df.output$",input$test3,sep=""),
        groups = as.factor(df.output$Cluster), 
        grid=FALSE,
        surface=FALSE,
        ellipsoid=TRUE,
        ellipsoid.alpha=0.5,
        fit=smooth,
        xlab=input$test,
        ylab=input$test2,
        zlab=input$test3
      )
       par3d(mouseMode = "trackball")
       rglwidget() 
     })
})   
4

1 回答 1

0

你的代码

x = paste("df.output$",input$test,sep="")

将 x 设置为长度为 1 的字符向量。如果要从数据框中选择组件,请使用

x = df.output[[input$test]]

您的代码也没有使用包含的包scatter3d(它不是rgl函数)。包中有一个具有该名称的函数,并且car包中有一个类似的名称plot3D

于 2017-07-16T11:02:29.147 回答