我正在使用这个抵押贷款计算器应用程序而我无法显示输出值。它应该产生每月付款,然后是基于收入抵押是否负担的标志。
我似乎无法弄清楚它为什么没有产生输出。这些公式在作为单独的R脚本运行时都有效。
这是我的server.R文件:
library(shiny)
shinyServer(
function(input, output){
output$pitiPayment <- renderText({piti(input$tax, input$insurance, input$principal, input$annualInterest, input$loanTerm, input$downPayment) })
output$Affordable <- renderText({affordability(input$tax, input$insurance, input$principal, input$annualInterest, input$loanTerm, input$downPayment, input$income)})
}
)
monPayment <- function(principal, annualInterest, loanTerm, downPayment) {
monthlyInterest <- annualInterest/(12 * 100)
termMonths <- 12 * loanTerm
monthlyPayment <- round((principal-downPayment)*monthlyInterest/(1-(1+monthlyInterest)^(-termMonths)),2)
return(monthlyPayment)
}
piti <- function(tax, insurance, principal, annualInterest, loanTerm, downPayment) {
monthlyPayment <- monPayment(principal, annualInterest, loanTerm, downPayment)
taxPayment <- (principal*(tax/100))/12
insurancePayment <- ((insurance/100)*principal)/12
monthly <- round(monthlyPayment + taxPayment + insurancePayment,2)
return (monthly)
}
affordability <- function(tax, insurance, principal, annualInterest, loanTerm, downPayment, income) {
pitiPayment <- piti(tax, insurance, principal, annualInterest, loanTerm, downPayment)
pctofIncome <- pitiPayment/income
if (pctofIncome > 0.3){
affordable <- "This loan is not affordable."
} else {
affordable <- "This loan is affordable."
}
return(affordable)
}
这是我的ui.R文件:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Mortgage Calculator"),
sidebarPanel(
h4('Property'),
textInput('text', 'Address', value='123 Elm'),
numericInput('principal', 'Price ($)', 250000),
numericInput('downPayment', 'Down Payment ($)', 50000),
h5('Mortgage Info'),
numericInput('annualInterest', 'Mortgage Rate (excl % sign)', 6),
numericInput('Tax', 'Mil rate ($ per $100 valuation)', 3.5),
numericInput('loanTerm', 'Loan Term in years', 30),
h5('Mortgage Info'),
numericInput('insurance', 'Insurance cost, as a % of value (excl % sign)', 2),
h5('Income'),
numericInput('Income', 'Monthly Income', 6000)
),
mainPanel(
h4('Total Housing Cost Per Month'),
textOutput("pitiPayment"),
h4('Affordable?'),
textOutput("Affordable"),
br(),
h4('Instructions'),
helpText("This application calculates the 'PITI payment' for a given property and mortgage, the total monthly cost including mortgage, insurance and taxes."),
code("monPayment"),
helpText("Enter the property's cost, the amount of down payment, the tax rate and the insurance cost to calculate the monthly cost of ownership."),
code("affordability"),
helpText("Enter your monthly income to determine if the mortgage is affordable; affordability is defined as 30% of monthly income.")
)
))