'Reactive' hash


#1

I would like to store the values of a set of numeric inputs into a single hash so that whenever the user changes one of them the hash is updated, kind of:

shinyServer(function(input, output, session) {
   tpl_info_A = reactive({hash(
    "TPL_EmissionsLimit"  = input$total_emissions
  )})
   
  #OUTPUT
  output$display <- renderPrint({
    return(as.character(tpl_info_A[["TPL_EmissionsLimit"]]))
    #return(as.character(input$total_emissions))
  })
...

but when I try to look at the value via the hash as in the display I get:

Error: object of type 'closure' is not subsettable

what am I missing?

Thanks for your help!


#2

You’re only missing two brackets/parentheses!

When you use a reactive expression elsewhere (e.g. in your renderPrint() call) you need to use () after the reactive name.

So you can change your renderPrint() to:

output$display <- renderPrint({
  as.character(tpl_info_A()[["TPL_EmissionsLimit"]])
})

(I removed the return() call, too, as you don’t need it).

For a good start to understanding reactivity, I’d recommend checking out the videos from the Shiny developer conference.