-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.R
46 lines (38 loc) · 1.33 KB
/
server.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
# This is the server logic of a Shiny web application. You can run the
# application by clicking 'Run App' above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
#caculate the BMI
#Calculate function
BMI <- function(height,weight) weight/(height)^2
# Print the result
shinyServer(function(input, output) {
output$result <- renderPrint({
w <- as.numeric(input$weight)
h <- as.numeric(input$height)
if (w<0||h<0){
'Wrong input, please input proper number'
} else {
BMI(input$height,input$weight)}
})
output$status <- renderPrint({w <- as.numeric(input$weight)
h <- as.numeric(input$height)
bmi <- w/h^2
if (w<0||h<0){
'Wrong input, please input proper number'
} else if(bmi<18.5) {
'underweight'
} else if(bmi>18.5&&bmi<25){
'Normal'
} else if(bmi>=25)
{
'overweight'
}
})
}
)