我正在尝试创建一个快速应用程序,让用户选择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()
})
}) 发布于 2017-07-16 11:02:29
你的代码
x = paste("df.output$",input$test,sep="")将x设置为长度为1的字符向量。如果要从dataframe中选择组件,请使用
x = df.output[[input$test]]您的代码也不使用包含scatter3d的包(它不是rgl函数)。在car包中有一个具有该名称的函数,在plot3D包中有一个类似的名称。
https://stackoverflow.com/questions/45126888
复制相似问题