-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.R
More file actions
44 lines (35 loc) · 1015 Bytes
/
server.R
File metadata and controls
44 lines (35 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# Load library
library(shiny)
# Function to calculate monthly payment
mortgage <- function(loanAmount, interestRate, loanTerm) {
# Monthly interest
mInterest <- interestRate / 12
# Auxiliar term
term <- 1 + mInterest / 100
# Calculate monthly amount
amount <- loanAmount * mInterest / ( 100 * (1 - term^(-12*loanTerm) ))
# return amount
if (is.nan(amount)) 0
else amount
}
# Server function
shinyServer(
function(input, output) {
# Put calculated data in output var
output$result <- renderTable({
# Calculate
m <- mortgage(input$loanAmount, input$interestRate , input$loanTerm)
rows <- c("Monthly:", "Yearly:")
# Label data
a <- c("Monthly:", "Yearly:")
# Calculated data
b <- c(m,m*12)
# Create dataframe
df <- data.frame(a,b)
# Assign names to columns
colnames(df) <- c("","Amount (€)")
# Print dataframe
print(format(df, digits=2))
})
}
)