I'm trying to include a dataset in a Shiny app that first gets read in and used as is, e.g. by displaying it as a table. I would like to allow the user to then be able to manipulate this dataset and update the same table output with the updated dataset.
I can get both parts to work separately - I can display the original data, and I can display reactive updated data. But I can't figure out how to get both to work using the same dataset? The below code is a simple example using iris, with an attempt to display the original dataset and then rbinding it so there are twice as many rows to display in the updated dataset when you hit 'Run'. Note that I've converted the data to data.table because my actual code will be using data.table a lot.
library(shiny)
library(data.table)
iris <- as.data.table(iris)
ui <- fluidPage(
fluidRow(column(4, actionButton("run", "Run"))),
fluidRow(column(12, tabPanel(title = "tab1",
DT::dataTableOutput("table1"))))
)
server <- function(input, output, session) {
irisdata <- reactive({
irisdata <- iris
})
irisdata <- eventReactive(input$run, {
rbind(irisdata(), iris, fill = TRUE)
})
output$table1 <- DT::renderDataTable({
irisdata()
})
}
shinyApp(ui, server)
The rbind results in: Error in : evaluation nested too deeply: infinite recursion / options(expressions=)?
Which is to be expected I suppose as it's self-referencing, but I can't figure out how to write the code otherwise?