2017-07-16 105 views
0

我正在尝试创建一个快速应用程序,让用户选择3个变量并使用scatter3D重新生成3D散点图。在使用闪光灯时我一直都会碰到这个错误,我看不出来纠正它。使用scatter3d和Shiny动态生成绘图

Error: not all arguments have the same length

我的代码也可以,如果更换:

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

回答

0

您的代码

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

设置x到一个长度为1的字符向量。如果您想选择从数据帧的组成部分,使用

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

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

+0

谢谢!现在工作。对不起,图书馆混在一起。这正是你有什么,除了我有x = df.output [,输入$测试]。 – dchow