See the code below - what should happen is, when you press the button, it displays table1 and table2, but what actually happens is you get table2 twice.
It works correctly if you write out both statements without the loop, but this isn't an option for my actual app. Have also tried isolate(i) (even though it's not reactive).
How can I get this to work?
library(shiny)
ui <- fluidPage(
tableOutput("test1"),
tableOutput("test2"),
actionButton("button", "Press me!")
)
server <- function(input, output, session) {
tables <- list(table1 = data.frame(a = 1:4, b = 1:4), table2 = data.frame(c = 5:8, d = 5:8))
observeEvent(input$button, {
for(i in 1:2) {
output[[paste0("test", i)]] <- renderTable(tables[[paste0("table", i)]])
}
})
}
shinyApp(ui, server)