【问题标题】:Simple Shiny Code with argument missing缺少参数的简单闪亮代码
【发布时间】:2014-09-21 18:14:48
【问题描述】:

我刚刚开始使用 Shiny,并且一直在使用数据集来尝试获得一些经验。我已经为相当多的迭代重新编写了一个简单的代码,并不断收到 ...argument is missing 且没有默认值。有人看到我错过了什么吗?

ui.R
=============================
library(shiny)

shinyUI(
  pageWithSidebar(

    headerPanel("Simple Cluster Example"),

    sidebarPanel(   
      numericInput("var", "Cluster:", 2,
                   min = 2, max = 5, step = 1)),

    mainPanel(
      plotOutput("plot"),  
      #dataTableOutput("table")
    )
  )
)
-------------------------------

server.R
===============
library('shiny')
library('ggplot2')
shinyServer(function(input, output) {  


  protein <- read.csv("protein.csv")
  vars.to.use <- colnames(protein) [-1]
  pmatrix <- scale(protein[,vars.to.use])
  pcenter <- attr(pmatrix, "scaled:center")
  pscale <- attr(pmatrix, "scaled:scale")
  d <- dist(pmatrix, method="euclidean")
  pfit <- hclust(d, method="ward.D")

  # This code is triggered whenever the drop-down menu is changed in the UI
  component <- input$var
  #rect.hclust(pfit, k=component)
  groups <- cutree(pfit, k=component)
  princ <- prcomp(pmatrix)
  nComp <- 2
  project <- predict(princ, newdata=pmatrix) [,1:nComp]
  project.plus <- cbind(as.data.frame(project),
                        cluster=as.factor(groups),
                        country=protein$Country)
  p <- ggplot(project.plus, aes(x=PC1, y=PC2)) +
    geom_point(aes(shape=cluster))+geom_text(aes(label=country), hjust=0, vjust=1)

  output$plot <- renderPlot({print(p)})


})

【问题讨论】:

标签: r shiny


【解决方案1】:

你的问题是:

plotOutput("plot"),  

当您以“,”结尾时(因为您在后面注释掉了该行),它需要一个新参数。但在你的情况下它是空的,所以删除额外的“,”。

【讨论】:

  • 谢谢!在盯着那一点代码 4 小时后,我什至没有看到。我又做了一些改变,终于让它工作了。再次感谢您。
  • 当我第一次开始使用 Shiny 时,逗号会欺骗我好几个小时
猜你喜欢
  • 2021-03-10
  • 2020-10-31
  • 2014-03-15
  • 1970-01-01
  • 1970-01-01
  • 2018-07-26
  • 1970-01-01
  • 2014-05-31
  • 2013-04-10
相关资源
最近更新 更多