My shiny application doesn't work and I have no idea why : This tries to get an input and calculate the output and render the result in output$mortgagepayment. when I do run app it gives me the following message:
Error in .getReactiveEnvironment()$currentContext() : Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)
library(shiny)
# 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,
checkboxGroupInput("Fixed",
h3("Mortgage Year"),
choices = list("30 year" = 30,
"15 year" = 15,
"10 year" = 10),
selected = 1)),
# 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 = 1)),
column(3,
numericInput("percentageDown",
h3("Percentage Down"),
value = 1),min=0,max=1) ,
column(3, numericInput("mortgageYield", h3("Mortgage Yield"), value=0.0, min = 0, max = 0.1, step = NA,
width = NULL)),
),
fluidRow(
column(3, h3("Mortgage Payment"), verbatimTextOutput("mortgagepayment")))
)
# Define server logic ----
server <- function(input, output) {
housePrice = input$housePrice
downPayment = input$percentageDown
mortgageYield = input$mortgageYield
mortgageAmount = housePrice*(1-downPayment)
years = session$fixed
mortgagePayment = (mortgageAmount*mortgageYield)/(1-1/(1+mortgageYield)^(12*years))
output$mortgagepayment <-renderText({mortgagePayment})
}
# Run the app ----
shinyApp(ui = ui, server = server)