# Error of infinite recursion in R(Shiny)

I am working on R(Shiny) that is working on a loan prediction model. I am trying to calculate loan amount for a particular method but it is showing me an error for infinite recursion and just like mentioned in most of the posts even I have tried options(expressions = 1000) value, but am still experiencing the error.

If I write my condition as

``````MDBB_LA<- reactive({ input\$MDBB*10 })
``````

then it is giving me no error but if I add another condition on this as

``````DSCR_Post<- reactive({
if (input\$MU == "EMM" & (input\$EMIM/12)+EMI()!=0) {
EBITDA_EMM()/((input\$EMIM/12) + EMI())
} else if (input\$MU == "EMM" & (input\$EMIM/12)+EMI()==0) {
0
} else if (input\$MU != "EMM" & (input\$EMIM/12)+EMI()!=0 ){
EBITDA()/((input\$EMIM/12) + EMI())
}else{
0
}})

MDBB_LA<- reactive({ if ((input\$MU == "EMM" & DSCR_Post() >= 1) | (input\$MU == "FAT1" & DSCR_Post() >= 0.8) | (input\$MU == "FAT2" & DSCR_Post() >= 0.7) | (input\$MU == "UAT" & DSCR_Post() >= 0.5)) {
input\$MDBB*10*2
} else if ((input\$MU == "EMM" & DSCR_Post() < 1) | (input\$MU == "FAT1" & DSCR_Post() < 0.8 ) | (input\$MU == "FAT2" & DSCR_Post() < 0.7) | (input\$MU == "UAT" & DSCR_Post() < 0.5)){
input\$MDBB*10
} else if ((input\$MU == "MDBB1" ) | (input\$MU == "MDBB2" ) | (input\$MU == "MDBB3") | (input\$MU == "MDBB4") ){
input\$MDBB*10
} else {input\$MDBB*10}
})
``````

then it is showing me error as :

Warning: Error in : evaluation nested too deeply: infinite recursion / options(expressions=)?

Anyone who can help me, what is going wrong with the logical statement.

It likely means that you have two reactive variable definitions that call each other, so they can never terminate. Look at this very short example:

``````library(shiny)

ui <- fluidPage(
numericInput("num", "number", 5)
)

server <- function(input, output, session) {
x <- reactive({ y() })
y <- reactive({ x() + input\$num})
observe({
print(y())
})
}

shinyApp(ui, server)
``````

x calls y and y calls x, therefore there's infinite recursion. In your example, I assume that one of the variables `EMI` or `EBITDA_EMM` or `EBITDA` make a reference to `MDBB_LA()`, which results in an infinite recursion.