Sujay Nair
8/10/19
library(shiny)
shinyUI(fluidPage(
titlePanel("Compound Interest Calculator"),
sidebarLayout(
sidebarPanel(
helpText("This app will calculate compound interest given your inputs."),
numericInput("num_initial", label = h6("Enter the initial amount($)"), value = 100),
sliderInput("slider_interest_rate", label = h6("Input the annual interest rate(%)"), min = 0, max = 50, value = 5),
sliderInput("slider_years", label = h6("Input the number years"), min = 0, max = 20, value = 5),
actionButton("act_Solve", label = "Calculate")
),
mainPanel(
tabsetPanel(
tabPanel("Output",
p(h5("Your values:")), textOutput("initial"),
textOutput("interest_rate"), textOutput("years"),
p(h5("Calculated values:")),
textOutput("amount"), textOutput("interest")
),
tabPanel("Documentation",
p(h4("Compound Interest Calculator:")),
helpText("This app calculates compound interest and adds is to the initial amount")
)
)
)
)
))
<!–html_preserve–>
library(shiny)
shinyServer(function(input, output) {
values <- reactiveValues()
observe({
input$act_Solve
values$interest <- isolate({
input$num_initial * input$slider_interest_rate * input$slider_years/100
})
values$amt <- isolate(input$num_initial) + values$interest
})
output$initial_txt <- renderText({
input$act_Solve
paste("Initial Amount: [$]", isolate(input$num_initial))
})
output$interest_rate <- renderText({
input$act_Solve
paste("Interest Rate: ", isolate(input$slider_interest_rate),
" % per year")
})
output$years <- renderText({
input$act_Solve
paste("Time in years: ", isolate(input$slider_years)
)
})
output$interest <- renderText({
if(input$act_Solve == 0) ""
else
paste("Compound Interest [$]:", values$interest)
})
output$amount <- renderText({
if(input$act_Solve == 0) ""
else
paste("Total Amount [$]:", values$amt)
})
})
If we were to have an initial value of $625 and an interest rate of 5%, how much money would there be in 15 years?
Using the app, we obtain $1093.75