我刚刚开始使用Shiny并且一直在使用数据集来尝试获得一些经验。我已经为一些迭代重做了一个简单的代码并且继续得到...参数缺失而没有默认值。有谁看到我错过了什么?
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)})
})
答案 0 :(得分:1)
你的问题是:
plotOutput("plot"),
当你以“,”结束时(因为你之后注释掉了这一行),它需要一个新的参数。但在你的情况下它是空的,所以删除额外的“,”。