Elek J. Dobos
19-Feb-2017
The Shiny App will be used to calcluate the Body Mass Index (BMI) of a person. The user will provide two inputs into the Shiny ui.R page. The app will utilize Imperial System units (i.e. inches and pounds). The first input by the user will be their height in inches. The second input will be the weight of the user in pounds. Once the height and weight are entered in the ui.R page by the user the user must click the submit button. Once the submit button has been pressed by the user, the server.R page will calculate the users Body Mass Index (BMI).
ui.R page
<!– Load the necessary libaries –>
library(shiny)
library(knitr)
shinyUI(
pageWithSidebar(
headerPanel(“Body Mass Index (BMI) Calculator”),
<!– User will utilize the input controls and enter their height and weight –>
sidebarPanel(
numericInput('height', 'Height (inches)', 68, min = 36, max = 200, step = 1),
numericInput('weight', 'Weight (pounds)', 170, min = 50, max = 500, step = 1),
submitButton('Submit')
),
Display the output to the user.<BR>
mainPanel(<BR>
h3('Results:'),<BR>
h4('Your Body Mass Index Calcluator is '),<BR>
verbatimTextOutput("bmi"),<BR>
h5('BMI Weight Categories: '),<BR>
h5(' '),<BR>
h5(' '),<BR>
h5('BMI Weight Status'),<BR>
h5('------------------------------'),<BR>
h5('Below 18.5 Underweight'),<BR>
h5('18.5 - 24.9 Normal'),<BR>
h5('25 - 29.9 Overweight'),<BR>
h5('30+ Obese')<BR>
)<BR>
)
)
<!– server.R page –>
<!– Load the necessary libaries –>
library(shiny)
library(knitr)
<!– Calculation of the Body Mass Index (BMI) in Imperial Units –>
bmi <- function(height, weight) (weight * 703) / (height ^ 2)
shinyServer(
function(input, output) {
output$inputWeight <- renderPrint({input$weight})
output$inputHeight <- renderPrint({input$height})
<!– Send the calculated BMI back to the user interface so it can be displayed. –>
output$bmi <- renderPrint({bmi(input$height, input$weight) })
}
)
Click here for few samples runs…
Other supporting files:
https://github.com/EJD2016/github.io/blob/master/BMI.Rpres
https://github.com/EJD2016/github.io/blob/master/README_DDP_Project3.txt.txt
https://github.com/EJD2016/github.io/blob/master/ui.R
https://github.com/EJD2016/github.io/blob/master/server.R
https://github.com/EJD2016/github.io/blob/master/ShinyApp2.pdf