I'm trying to create a quick app that lets a user select 3 variables and regenerates a 3D scatter with scatter3D. I keep hitting this error when using shiny and I can't see to rectify it.
Error: not all arguments have the same length
My code also works if replace:
x = paste("df.output$",input$test,sep=""),
y = paste("df.output$",input$test2,sep=""),
z = paste("df.output$",input$test3,sep=""),
with
x = df.output$age_scaled
y = df.output$freq_scaled
z = df.output$bonus_scaled
My ui function looks like this
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)
)
))
Server function looks like this
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()
})
})
Your code
x = paste("df.output$",input$test,sep="")
sets x to a length 1 character vector. If you want to select a component from a dataframe, use
x = df.output[[input$test]]
Your code also doesn't use the package containing scatter3d
(it's not an rgl
function). There's a function with that name in the car
package, and a similar name in the plot3D
package.