[英]Dynamically Generating Plot with scatter3d and Shiny
我正在嘗試創建一個快速的應用程序,允許用戶選擇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()
})
})
您的密碼
x = paste("df.output$",input$test,sep="")
將x設置為長度為1的字符向量。 如果要從數據框中選擇組件,請使用
x = df.output[[input$test]]
您的代碼也沒有使用包含scatter3d
的軟件包(它不是rgl
函數)。 car
包裝中有一個帶有該名稱的函數,而plot3D
軟件包中具有一個相似的名稱。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.