29/12/2018

Introduction

  • For the purpose of the course 'Developing Data Products' I developed a Shiny app that emulates a very simple calculator.

  • The user places the first number, the second number and the operator ("+","-","x", "÷") and (s)he gets the result.

  • The application is accessible from this link: https://mx354.shinyapps.io/Developing_Data_Products_Project/

  • In the next slides we will present the code that was written for the ui.R and server.R files.

ui.R file

library(shiny)
shinyUI(fluidPage(
    titlePanel("Simple Shiny Calculator"),
    sidebarLayout(
        mainPanel(
        h5("This is a simple calculator. 
        You put the first and the second number,
        select the operator and voila!"),
        numericInput("num1", "Select the first number", 0),
        numericInput("num2", "Select the second number", 0),
        selectInput("operator", "Select the operator",
        choices = c("+","-","x", "÷"))
        ),
        mainPanel(
        h2("The result is:"),
        textOutput("output")
        ))))

server.R file

library(shiny)
shinyServer(function(input, output) {
        output$output <- renderText({
                switch(input$operator,
                       "+" = input$num1 + input$num2,
                       "-" = input$num1 - input$num2,
                       "x" = input$num1 * input$num2,
                       "÷" = input$num1 / input$num2)
                
        })
        
})

Resulting Application

The application looks like this:

ShinnyAppCalculator