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()
)