Thanks for reply.
I've read this example and implemented it with some differences. But when I run my app the following error message shows up on my screen:
palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
"#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))
shinyServer(function(input, output, session) {
# The selected file, if any
userFile <- reactive({
# If no file is selected, don't do anything
validate(need(input$file, message = FALSE))
input$file
})
# The user's data, parsed into a data frame
dataframe <- reactive({
read.csv(userFile()$datapath,
header = input$header,
sep = input$sep,
quote = input$quote)
})
output$contents = renderTable({dataframe()})
# Combine the selected variables into a new data frame
selectedData <- reactive({
filedata()[, c(input$xcol, input$ycol)]
})
clusters <- reactive({
kmeans(selectedData(), input$clusters)
})
output$kmeansPlot <- renderPlot({
par(mar = c(5.1, 4.1, 0, 1))
plot(selectedData(),
col = clusters()$cluster,
pch = 20, cex = 3)
points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
})
return(dataframe)
})
shinyUI(
navbarPage("", inverse = TRUE,
tabPanel("Prof. Antonio Sergio Ferraudo - Multivariate analysis"),
tabPanel("Cluster",
mainPanel(tabsetPanel(type = "tabs",
#Page showing data importing table
tabPanel("Data table",
sidebarPanel(width = 2,
fileInput('file', 'Choose CSV File',
accept=c('text/csv',
'text/comma-separated-values,text/plain',
'.csv')),
tags$hr(),
checkboxInput('header', 'Header', TRUE),
radioButtons('sep', 'Separator',
c(Comma=',',
Semicolon=';',
Tab='\t'),
','),
radioButtons('quote', 'Quote',
c(None='',
'Double Quote'='"',
'Single Quote'="'"),
'"')
),
tableOutput('contents')),
tabPanel("K-means clustering",
headerPanel('k-means clustering'),
sidebarPanel(width =2,
selectInput('xcol', 'X Variable', choices = colnames(dataframe)),
selectInput('ycol', 'Y Variable', choices = colnames(dataframe), selected = colnames(dataframe)[2]),
numericInput('clusters', 'Cluster count', 3, min = 1, max = 9)
),
plotOutput('kmeansPlot'))
) #end of tabsetPanel
) #end of mainPanel
), #end of tabPanel,
tabPanel("Principal component"),
navbarMenu("Coming up",
tabPanel("Correspondence"),
tabPanel("Discriminant"),
tabPanel("Factors")
)
)
)
Thanks again.