In Shiny tutorial, there is an example:
fib <- function(n) ifelse(n<3, 1, fib(n-1)+fib(n-2))
shinyServer(function(input, output) {
  currentFib         <- reactive({ fib(as.numeric(input$n)) })
  output$nthValue    <- renderText({ currentFib() })
  output$nthValueInv <- renderText({ 1 / currentFib() })
})
I don't get how reactive caches the values. Does it internally do something like return(function() cachedValue)?
Now I am wondering if I can do this?
fib <- function(n) ifelse(n<3, 1, fib(n-1)+fib(n-2))
shinyServer(function(input, output) {
  currentFib         <- reactiveValues({ fib(as.numeric(input$n)) })
  output$nthValue    <- renderText({ currentFib })
  output$nthValueInv <- renderText({ 1 / currentFib })
})
 
    