I was able to complete my first shiny application but I am not able deploy it on the web.This is the message I am getting:
Application successfully deployed to https://yaacov1.shinyapps.io/mortgage_calculator/
Error in func(fname, ...) : app.R did not return a shiny.appobj object. Can somebody please help? The deployment code is at the end
Code is here:
library(shiny)
library(rsconnect)
Define UI ----
ui <- fluidPage(
titlePanel("Basic widgets"),
fluidRow(
# column(3,
# h3("Buttons"),
# actionButton("action", "Action"),
# br(),
# br(),
# submitButton("Submit")),
# column(3,
# h3("Single checkbox"),
# checkboxInput("checkbox", "Choice A", value = TRUE)),
column(3,selectInput("Fixed", "Fixed:",
c("30 year" = "30",
"15 year" = "15",
"10 year" = "10")),
tableOutput("data")),
# column(3,
# dateInput("date",
# h3("Date input"),
# value = "2014-01-01"))
),
fluidRow(
# column(3,
# dateRangeInput("dates", h3("Date range"))),
#
# column(3,
# fileInput("file", h3("File input"))),
column(3,
numericInput("housePrice",
h3("Housing Price"),
value = 100000)),
column(3,
numericInput("percentageDown",
h3("Percentage Down"),
value = 0.2),min=0,max=1) ,
column(3, numericInput("mortgageYield", h3("Mortgage Yield"), value=0.05, min = 0, max = 0.1, step = NA,
width = NULL)),
),
fluidRow(
column(3, h3("Mortgage Payment"), verbatimTextOutput("mortgagepayment"))),
mainPanel(tableOutput("mytable"),
#DT::dataTableOutput("AmortizationTable")
plotOutput("paymentchart"))
)
Define server logic ----
server <- function(input, output) {
output$mortgagepayment <- renderText({
# prevent this block from trying to calculate when other fields are
# empty or invalid
req(input$housePrice, input$percentageDown, input$mortgageYield, input$Fixed)
# message("calculate!") # just advises when this block fires
housePrice = input$housePrice
downPayment = input$percentageDown
mortgageYield = input$mortgageYield/12
mortgageAmount = housePrice*(1-downPayment)
years = as.numeric(input$Fixed)
mortgagePayment = (mortgageAmountmortgageYield)/(1-1/(1+mortgageYield)^(12years))
})
# now calculate the amortization table (Principal + interest at each stage )
output$mytable <- renderTable({
# prevent this block from trying to calculate when other fields are
# empty or invalid
req(input$housePrice, input$percentageDown, input$mortgageYield, input$Fixed)
# message("calculate!") # just advises when this block fires
years = as.numeric(input$Fixed)
housePrice = input$housePrice
downPayment = input$percentageDown
mortgageYield = input$mortgageYield/12
mortgageAmount = housePrice*(1-downPayment)
mortgagePayment = (mortgageAmountmortgageYield)/(1-1/(1+mortgageYield)^(12years))
years = as.numeric(input$Fixed)
numofPayments =seq(1:(years12))
principalOutStanding = (1+mortgageYield)^(numofPayments-1)
t= (1+mortgageYield)^(numofPayments-1)
t=(t-1)/(1-1/(1+mortgageYield)^(12years))
principalOutStanding = mortgageAmount * (principalOutStanding - t )
interestpaid = principalOutStandingmortgageYield
principalPaid = mortgagePayment - interestpaid
res<-data.frame(month=seq(1:(years12)),payment = rep(mortgagePayment,years12),Principal_outstanding=principalOutStanding, interest_paid = interestpaid, principal_Paid = principalPaid )
})
output$paymentchart <- renderPlot({
# prevent this block from trying to calculate when other fields are
# empty or invalid
req(input$housePrice, input$percentageDown, input$mortgageYield, input$Fixed)
# message("calculate!") # just advises when this block fires
years = as.numeric(input$Fixed)
housePrice = input$housePrice
downPayment = input$percentageDown
mortgageYield = input$mortgageYield/12
mortgageAmount = housePrice(1-downPayment)
mortgagePayment = (mortgageAmountmortgageYield)/(1-1/(1+mortgageYield)^(12years))
years = as.numeric(input$Fixed)
numofPayments =seq(1:(years12))
principalOutStanding = (1+mortgageYield)^(numofPayments-1)
t= (1+mortgageYield)^(numofPayments-1)
t=(t-1)/(1-1/(1+mortgageYield)^(12years))
principalOutStanding = mortgageAmount * (principalOutStanding - t )
interestpaid = principalOutStandingmortgageYield
principalPaid = mortgagePayment - interestpaid
res<-data.frame(month=seq(1:(years12)),payment = rep(mortgagePayment,years*12),Principal_outstanding=principalOutStanding, interest_paid = interestpaid, principal_Paid = principalPaid )
plot(res$month, res$interest_paid, type='l',col="red")
lines(res$month, res$principal_Paid,col="green")
})
}
Run the app ----
#shinyApp(ui = ui, server = server)
rsconnect::setAccountInfo(name='yaacov1',token='E1516640B752D8F37BB8050548A5E329',secret='9kzmCcmXcrrCljUzqWHhO0KRoGonjPxdPDlW61L8')
deployApp()