Chick Weight App

Mridula

January 20, 2017

Chick Weight App

Welcome…

  weight Time Chick Diet
1     42    0     1    1
2     51    2     1    1
3     59    4     1    1
4     64    6     1    1
5     76    8     1    1
6     93   10     1    1

Summary of the Data

ui.R

library(shiny)
shinyUI(fluidPage(
  titlePanel("Chick Weights With Different Diets"),
    sidebarLayout(
    sidebarPanel(
      helpText("Select Variables to See the Relationship"),
      selectInput("xcol", "X Variable", names(ChickWeight[,3:4])),
      selectInput("ycol", "Y Variable", names(ChickWeight[,1:2])),
      numericInput("clusters", "Number of Clusters", 3, min = 1, max = 21)
    ),
    # Show a plot of the generated distribution
    mainPanel(
      tabsetPanel(
        tabPanel("Plot", plotOutput("Plot")),
        tabPanel("User Guide", verbatimTextOutput("User Guide"))
      )
    )
  )
)) 

server.R

library(shiny)
shinyServer(function(input, output, session) {
  inputData <- reactive({ChickWeight[,c(input$xcol, input$ycol)]})
  clusters <- reactive({kmeans(inputData(), input$clusters)})
  output$Plot <- renderPlot({
    
    palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
              "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))
    plot(inputData(),
         col = clusters()$cluster,
         pch = 20,
         cex = 3)
    points(clusters()$centers, 
           pch = 25, 
           cex = 2, 
           col = "orange", 
           bg = "purple")
    })
  output$`User Guide` <- renderText("This graph depicts the relationships between different variables.

Select one variable each for X-axis and Y-axis, and see how 
the response varables (y-axis) change based on changing predictor values (x-axis).")
})

Link to the App: https://vmridula.shinyapps.io/ChickWeight/