2017-07-16 37 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