Reavtivity question

Hi guys,

I have a question related to reactive values to better understand those. I was trying to create a reactive value with reactiveVal for which the content should be the subset of a different reactive value and the filtering based on a user input. Basically something like that:

reactiveValue_2 <- reactiveVal(reactiveValue_1()[ID == input$selectedId])

However, this gives me the error 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.). When I put everything into something like that, it works:

reactiveValue_2 <- reactiveVal()
observeEvent(input$selectedId, {
    reactiveValue_2(reactiveValue_1()[ID == input$selectedId])
})

Could somebody explain to me why the first reason does not work? I would love to understand the mechanics behind that.

Best regards
Jakob

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