Why doesn't this renderTable function need a dependency on a button to get updated? (It's using isolate)

I'm looking at some code from the "More Widgets" example of R Shiny, which you can see yourself by running runExample("07_widgets")

One part of this code has the following (this is in the server section):

output$view <- renderTable({
    head(datasetInput(), n = isolate(input$obs))
  })

There is a button elsewhere in the code (in the sidebar panel section) created using actionButton("update", "Update View")

Somehow, the table is updated every time the "update" button is clicked. How can this be? The table does not have a dependency on the actionButton?

I would expect the table to update whenever the button was clicked only if it was created as follows:

output$view <- renderTable({

    #take a dependency on the "update" button
    input$update

    head(datasetInput(), n = isolate(input$obs))
  })

(This method is described here: https://shiny.rstudio.com/articles/isolation.html)

But as it stands, the table creation is missing the input$update line that creates the dependency...

I understand why the table appears - because the renderTable block is run once as the app starts. But I don't understand why it updates every time the "update" button is clicked. I would think that it should never update again, because it is not dependent on anything (since the only dependency it could have, on input$obs, is broken with isolate())

 datasetInput <- eventReactive(input$update,

this causes datasetInput to be recalculated on input$update event.
the rendering is automatic based on the invalidation of that datasetInput, so indirectly its depended on input$update

1 Like

Thank you! Didn't realize that. So is the function “datasetInput()” what we’d call a reactive conductor?

yes, precisely. That's correct.

1 Like

Okay, good to know. So just to make sure I get it, any function that has datasetInput() in it will be run every time datasetInput() is run, correct? thanks again for the help by the way

yes, but there are exceptions.
It wouldnt be so if you explicitly isolate() it , nor if its in the expr block of an observeEvent or eventReactive.

1 Like

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