Ngwoke Chukwubuikem
28 September, 2020
This is an RStudio shiny application developed as a part of final project in the Developing Data Products course in Coursera Data Science Specialization track. The application is a simple calculator
The project includes:
This app is hosted at: https://chu-ngwoke.shinyapps.io/calculator/
The reactivity of the shiny application widgets is controlled by using an Action Button. Based on user inputs, and using the simple arithemtic, the application displays the result of the calculation,
To make it easy for a novice user, a Documentation tab in the Main Panel of the application lists the details of the calculation of simple interest.
library(shiny)
shinyUI(fluidPage(
titlePanel("Simple Calculator"),
sidebarLayout(
sidebarPanel(
helpText("This app is a basic arithmetic calculator."),
numericInput("num_1", label = h6("Enter your first number"), value = 100),
numericInput("num_2", label = h6("Enter your second number"), value = 100),
selectInput("select_operation", label = h6(""), choices = c("*", "/", "+", "-")),
actionButton("action_Calc", label = "Refresh & Calculate")
),
mainPanel(
tabsetPanel(
tabPanel("Output",
h3("The result is:"),
textOutput("output")
),
tabPanel("Documentation",
p(h4("Simple Calculator:")),
helpText("This application calculates basic arithmetic on any two numbers, i.e. division, multiplication, addition or subtraction."),
)
)
)
)
))
library(shiny)
shinyServer(function(input, output) {
observe({input$action_Calc
if (input$action_Calc == 0) ""
else output$output <- renderText({
switch(input$select_operation,
"*" = input$num_1 * input$num_2,
"/" = input$num_1 / input$num_2,
"+" = input$num_1 + input$num_2,
"-" = input$num_1 - input$num_2)
})
})
}
)