March 8, 2019

BMI

-BMI is body mass index. BMI calculates whether your current height and weight are in the "Overweight", "Underweight", or "Normal Weight" category. Knowing your BMI is important to maintaining a healhty lifestyle.

-For my app, I made an app that not only calculates your BMI based on the height and weight you input, but it also places your BMI on a graph which shows where you fall in terms of your BMI and where you need to be to improve.

ui.R

First, I made my ui.R. I did this by first making an app that only calculated BMI, then made an app that returned which category certain BMIs fell into, and then combined them. After, I added the plot.

library(shiny)
shinyUI(fluidPage(titlePanel
                  ("Your BMI"),mainPanel(plotOutput("WeightPlot")),
sidebarPanel(numericInput
             ("hght","Height (in inches)",70,min = 1,max = 100),
numericInput("wght","Weight (in Pounds)",140,min = 1,max = 500),
submitButton("Submit"),h3("Your Exact BMI"),
textOutput(outputId="BMI"),h3("Your BMI Category"),
textOutput(outputId="Range")
)))

server.R

Next, I made a server.R. I made this by using the same steps as above.

shinyServer(function(input, output) {
    output$BMI <- renderText({input$wght/(input$hght*input$hght)*703})
    state <- reactiveValues()
    observe({state$x <- {input$wght/(input$hght*input$hght)*703}
      y <- reactive( if (state$x>24.99) "Overweight" else if 
                  (state$x<18.5) "Underweight" else "Normal Weight")
      output$Range <- renderText({ y() }) })
    output$WeightPlot <- renderPlot({
    plot(y=Height_and_Weight$Underweight,x=Height_and_Weight$Height,
           type="l",ylab="Weight",xlab="Height", col="red",
           main="A Normal BMI is Between These Two Red Lines")
    lines(y=Height_and_Weight$Overweight,x=Height_and_Weight$Height, 
            col="red")
      points(input$hght,input$wght,lwd=2,pch=15, col="Green")
})})

How to Read the Results

When you run the app, a few things will pop up.

-The first thing you need to do is put in your height (in inches) and weight (in pounds) on the right

-At the bottom, your BMI will come back and it will show you what range your BMI is in (either Overweight, Normal Weight, or Overweight)

-The graph on the left shows two red lines. These red lines mark the boundaries for being overweight (the top red line) or being underweight (the lower red line). Ideally, you would want to fall between those two red lines to be a normal weight.

-If your results return, "Overweight" or "Underweight" you can look at the graph to determine what weight range you should be in to be considered a normal weight.