I'm trying to store user input into a pre-existing dataframe in shiny.
In this simplified example I have a dataframe with a column labelled 'colour' and I want radio choice buttons to be able to assign values to each row in the dataframe, starting with row 1, then row 2 then row 3 etc. But it seems the dataframe always resets to the original value. What am I misunderstanding about shiny here?
library(shiny)library(tidyverse)library(DT)dataframe <- tibble(row_id = c(1,2,3), colour = c("","",""))ui <- fluidPage( radioButtons("colour","Pick a colour:", choices = c("blue","green","red")),actionButton("next_button", "Pick the next colour"),DTOutput("dataframe"))server <- function(input, output) {vals <- reactiveValues(active_row = 1) observeEvent(input$next_button,{ dataframe[vals$active_row, "colour"] = input$colour # view(dataframe) # print(vals$active_row) vals$active_row = vals$active_row + 1 output$dataframe <- renderDataTable(dataframe) })}# Run the application shinyApp(ui = ui, server = server)