我正在尝试创建一个快速应用程序,让用户选择 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()
})
})