Quantcast
Channel: Update specific row and column of dataframe - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Update specific row and column of dataframe

$
0
0

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)

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>