【问题标题】:Dynamically Generating Plot with scatter3d and Shiny使用 scatter3d 和 Shiny 动态生成绘图
【发布时间】:2017-07-16 09:10:07
【问题描述】:

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

【问题讨论】:

    标签: r shiny rgl r-car scatter3d


    【解决方案1】:

    你的代码

    x = paste("df.output$",input$test,sep="")
    

    将 x 设置为长度为 1 的字符向量。如果要从数据框中选择组件,请使用

    x = df.output[[input$test]]
    

    您的代码也没有使用包含scatter3d 的包(它不是rgl 函数)。 car 包中有一个具有该名称的函数,plot3D 包中有一个类似的名称。

    【讨论】:

    • 谢谢!现在工作。对不起图书馆混淆了。这正是你所拥有的,除了我有 x=df.output[,input$test]。
    猜你喜欢
    • 2017-02-05
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 2015-10-31
    • 2014-04-19
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多