How to define variables just once and use in different renders.

I have what I feel is quite a low level question, but have struggled to find an answer nonetheless. Currently for each output I have defined variables within, such as 'L0' here :
output$loanamount <- renderText({ L0 <- isolate(input$price) - ((isolate(input$deposit))/100)*isolate(input$price) paste(sep='',"Loan Amount: £",L0) })
However, when creating a new output using some of the same variables, I have to redefine them, like in this case with L0 : output$mortgagepayments <- renderText({ intrate <- ((isolate(input$apr))/(100*12)) L0 <- isolate(input$price) - ((isolate(input$deposit))/100)*isolate(input$price) bottomdiscount <- L0*intrate topdiscount <- 1- 1/(1+intrate)^(12*isolate((input$term))) mortgagepayments <- bottomdiscount/topdiscount paste(sep='',"Monthly Mortgage Payments: £",round(mortgagepayments,2)) })
What I would like to know is if there is a way I can define say 'L0' once somewhere in the server and then call on it within a render, without having to redefine it for each new render. I hope this makes sense. Many thanks in advance!

L0 <- reactive({ input$price - 
    (input$deposit/100)*input$price})

which I think from algebra is equivalent to :

L0 <- reactive({ input$price * ( 1- input$deposit/100)) })

and use it as a reactive
i.e.

output$loanamount <- renderText({ paste(sep='',"Loan Amount: £",L0()) })

Ah yes, this will work perfectly. Thank you very much for your fast answer!

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.