October 11, 2017

Description

The App calculates 3 simple mathematical operation i.e Addition, Substraction and Multiplication.

User need to select two numbers in the inputs and in the select input the operation needs to be selected, The output will show in the main panel.

The working App can be accessed at https://biswajeet135.shinyapps.io/Calculator/

Shiny UI Code

The UI code that constructs the panels is given below.

library(shiny)

shinyUI(fluidPage(
 titlePanel("Simple Calculator"),
 sidebarLayout(
    sidebarPanel(
        numericInput("first", "Select a Number", 10),
        numericInput("second", "Select Another Number", 10),
        selectInput("ops", "Select Operation",
              choices = c("Addition","Substraction","Multiplication"))
      
    ),
    mainPanel(
        h2("The final result is:"),
       textOutput("oput")
    )
  )
))

Server Side Shiny Code

The server side code that accepts the user inputs and computest the result is given below.

library(shiny)

shinyServer(function(input, output) {
   
  output$oput <- renderText({
    
      switch(input$ops,
             "Addition" = input$first + input$second,
             "Substraction" = input$first - input$second,
             "Multiplication" = input$first * input$second)
    
  })
  
})

Thank You