Created
April 7, 2013 12:37
-
-
Save reinholdsson/5330332 to your computer and use it in GitHub Desktop.
Shiny savings app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(rHighcharts) | |
shinyServer(function(input, output) { | |
.data <- reactive({ | |
interest <- 1 + ( as.integer(input$interest) / 100 ) | |
start <- as.numeric(input$start) | |
monthly <- as.numeric(input$monthly) | |
years <- as.integer(input$years) | |
x <- start | |
for (y in 1:years) { | |
for (m in 1:12) { | |
start <- start + monthly * interest^(m/12) | |
} | |
start <- start * interest | |
x <- c(x, start) | |
} | |
return(x) | |
}) | |
output$results <- renderChart({ | |
a <- rHighcharts:::Chart$new() | |
a$chart(type = "column") | |
a$legend(enabled = FALSE) | |
a$title(text = "Forecast") | |
a$yAxis(title = list(text = "Amount")) | |
a$xAxis(title = list(text = "Years")) | |
a$data(x = .data(), name = "Amount") | |
return(a) | |
}) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(rHighcharts) | |
shinyUI(pageWithSidebar( | |
headerPanel(""), | |
sidebarPanel( | |
textInput("start", "Start amount", value = 0), | |
textInput("monthly", "Monthly savings", value = 1000), | |
sliderInput("interest", "Yearly interest rate (%)", min = 0, max = 20, value = 5, step = 1), | |
sliderInput("years", "Number of years to show", min = 1, max = 100, value = 20, step = 1) | |
), | |
mainPanel( | |
chartOutput("results") | |
) | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment