0

The values of my inputs are not changed after the first update of my reactive value. I adapted the code from here and here.

library(data.table)
library(shiny)
library(shinydashboard)
library(DT)

ui <- fluidPage(
  dashboardPage(
    dashboardHeader(title = ""),
    dashboardSidebar(fluidRow(column(12,actionButton("submit","Update")))),
    dashboardBody(dataTableOutput('myTableOutput')
    )
  )
)

RV<-reactiveValues()
RV$repTable <- data.table(Blocs=c(1,2,3), Vehicules=c("a","a","a") )


server <- function(session, input, output) {
  
  output$myTableOutput = DT::renderDataTable({
    
    toShow<-RV$repTable
    vehicles <- vector(mode = "character", length = 0)
    for(i in 1:nrow(toShow))
       vehicles[i] <- as.character(selectInput(inputId=paste0("row_select_", i), label=NULL, choices=c("a","b"),selected=RV$repTable[i,"Vehicules"]))

    toShow$Vehicules<-vehicles
    toShow
    },
    escape=FALSE,selection = 'none',
    options = list(pageLength = 100,info = FALSE, dom="t",
                  preDrawCallback = JS('function() { Shiny.unbindAll(this.api().table().node()); }'),
                  drawCallback = JS('function() { Shiny.bindAll(this.api().table().node()); } ')
                  )
    )
 

  observeEvent(input$submit,{
    
    print("Those are the old and new values:")
    for(i in 1:nrow(RV$repTable)) 
      print(paste0("Old: ",RV$repTable[i,"Vehicules"], " New: ",input[[paste0("row_select_", i)]]))

    print("Perform updating...")
    for(i in 1:nrow(RV$repTable)) 
      RV$repTable[i,"Vehicules"]<-input[[paste0("row_select_",i)]]#[[1]]

    print("Those are the values after updating:")
    for(i in 1:nrow(RV$repTable)) 
      print(RV$repTable[i,"Vehicules"][[1]])

  })
}

shinyApp(ui = ui, server = server)

This is the current behaviour: When I change some inputs and then click the button "Update" for the first time, everything works fine. I mean, the "Old" and "New" values are identified, RV$repTable is updated and the updated values are shown.

If I modify the inputs and click "Update" again, the values "Old" values are identified but the "New" are not, so RV$repTable is not updated neither. What I expect is the "New" values (inputs) to be updated also, ¿What am i doing wrong?. This is my log:

enter image description here

enter image description here

Lev
  • 693
  • 1
  • 8
  • 24

0 Answers0