R/shiny

BMI 구하기

이부일 2018. 10. 17. 16:54

#install.packages("shiny")

library(shiny)


ui <- fluidPage(titlePanel("BMI"),

                

                sidebarPanel(numericInput(inputId = "weight", label = "Weight(kg)", value = 70, min = 0, max = 300),

                             numericInput(inputId = "height", label = "Height(cm)", value = 170, min = 0, max = 200),

                             submitButton(text = "Submit")),

                

                mainPanel(h3("Results"),

                          h4("Weight"),

                          verbatimTextOutput("weight"),

                          h4("Height"),

                          verbatimTextOutput("height"),

                          h4("BMI"),

                          verbatimTextOutput("BMI")))


server <- function(input, output){

  bmi_calcuation <- function(weight, height){

    weight / (height/100)^2

  }

  

  output$weight <- renderPrint({input$weight})

  output$height <- renderPrint({input$height})

  output$BMI    <- renderPrint({bmi_calcuation(input$weight, input$height)})

}


shinyApp(ui = ui, server = server)


[출처] 김진형 교수의 아빠가 들려주는 shiny app 만들기