Overview of the code
library(shiny)
ui <- fluidPage(
pageWithSidebar(
headerPanel('Cars K-means clustering'),
sidebarPanel(
selectInput('xcol', 'X Variable', names(mtcars)),
selectInput('ycol', 'Y Variable', names(mtcars),
selected=names(mtcars)[[2]]),
numericInput('clusters', 'Cluster count', 3,
min = 1, max = 9)
),
mainPanel(
plotOutput('plot1'),
textOutput(outputId = "desc")
)
)
)
server <- function(input, output, session) {
# Combine the selected variables into a new data frame
selectedData <- reactive({
mtcars[, c(input$xcol, input$ycol)]
})
clusters <- reactive({
kmeans(selectedData(), input$clusters)
})
output$plot1 <- 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)
})
output$desc <- renderText({
"Documentation can be found at:https://github.com/whyler12/ddp"
})
}
shinyApp(ui, server)
## PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.