Iteratively save shiny changes into input dataframe

Hi,

I'm sorry that this is a basic question. I'm new to shiny and still getting my head around reactive programming.

I'm creating a shiny app for quality control of a large data.frame, that needs a human to manually examine each row. Essentially, I want to show a row of a data.frame on the screen, then the user presses a button which updates a "reject" column.

Despite getting lots of the reactive tutorials to run, I'm really struggling on the reactive bit here.

There's a reproducible simplified version below. What I would like is

  • for the radio buttons to update the "reject" column for each row based on the radio button
    • both on the screen
    • but also in the reject column of the data.frame itself, so it exists after the shinyapp has been closed down

I know the answer is probably really simple and I'm guessing something to do with updateRadioButtons, observe or isolate. But I just can't work it out and I would love some pointers if someone has 5 mins spare.

tablein <- data.frame(Data=c("Hello","Goodbye","Maybe"),Data2=c(1,2,3),reject=FALSE)

ui <- fluidPage(
  # Plot the row of the table
  DT::dataTableOutput("table"),
  hr(),
  # Now add whether you have screened it or not
  fluidRow(
    column(3,offset=1,htmlOutput("reject"))
  ),

  hr(),
  
  fluidRow(
    column(3,radioButtons(inputId = "toreject",
                       label = "Do you reject?",
                       choices =c("reject","keep")))),
    
  hr(),
  
  # And scroll through the table 
  fluidRow(
    column(3,
           sliderInput(inputId = "row",
                       label = "Row Number:",
                       min = 1,
                       max = 3,
                       value = 1)
    )
  )
)

server <- function(input, output,session) {
 
  YourData <- reactive(tablein[input$row,1:2])
  
  Reject <- reactive({
    YourText2 = as.character(data_bib$reject[input$row])
    if(isTRUE(YourText2)){YourText3 <- "REJECT!!"}else{YourText3 <- "Do not reject"}
    return(YourText3)
  })   
  
  output$table <- DT::renderDataTable({ data <- YourData() }, escape = FALSE) 
  
  output$reject <- renderUI({
    HTML(paste(Reject(), sep = '<br/>'))
  })
}

shinyApp(ui = ui, server = server)

Thanks,
Sam

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.