I have an app which creates boxes. Each box has a button that triggers a modal. The modal has inputs which the user changes and then a button which triggers an action based on those inputs (basically just uploading to a database). Because each box has a different specification, I wrote a module and then loop thru a list, creating a box for each element. This works fine.
However, the flow in the modal and observeEvent has a flaw: the first run thru I get the desired results, but on the second occasion in the same box (same id module), after pressing the modal button to update, it will not use the new inputs, but rather what happened in the first run. I am guessing it has something to do with the namespace/observeEvent combination as I might be triggering the event with a "stored" namespace? Would I need to somehow "flush" the namespace after every update? Anyway, any help appreciated as it gets confusing fast with all the namespace/modules combinations.
library(shiny)library(shinyWidgets)ui <- navbarPage('page', collapsible = TRUE, tabPanel("test", useSweetAlert(), sidebarLayout( sidebarPanel(), mainPanel( uiOutput('all_products_ui') ) ) )) # end navbarserver <- shinyServer(function(input, output) { list_products <- c(1,2,3,4,5) # Now, I will create a UI for all the products output$all_products_ui <- renderUI({ r <- tagList() progress_move <- 0 for(k in 1:length( list_products )){ r[[k]] <- ExistingProductUI(id = k, product = list_products[[k]] ) } r }) # handlers duplicate a call to module depending on the id of ExistingProductUI handlers <- list() observe( handlers <<- lapply(seq.int(length( list_products )), function(i) { callModule(ExistingProductUpdate, id = i, product = list_products[[i]] ) }) ) handlers}) # end of server ---- # UI module ------------------------------------------------------ExistingProductUI <- function(id, product){ ns <- NS(id) box(title = as.character(p$title), product["title"], footer = tagList( actionBttn( inputId = ns("change_selected"), label = "change"), ) )}# server module ------------------------------------------------------ExistingProductUpdate <- function(input, output, session, product){ ns <- session$ns observeEvent(input$change_selected, { # when box button is clicked for this product (id) # FIRST: show a modal showModal( modalDialog( title = "what do you want to change?", tagList( radioGroupButtons(inputId = ns("change_selected_choice"), labels = "change x", choices = c(1,2,3,4)), sliderInput(ns("change_selected_pct"), "change y:", min = -50, max = 100, value = 0, step = 5) ), easyClose = TRUE, footer = tagList( actionButton(ns("change_selected_submit"), "submit!", icon = icon("check")), modalButton("never mind") ) ) ) # SECOND: when change_selected_submit is clicked, observeEvent(input$change_selected_submit, { # do some calculations with product using what I inputed in modal --- # then, update a table ---- functionToUploadThings(product, input$change_selected_choice) # THIRD: Close with a confirmation sendSweetAlert( session, title = "Success!", type = "success", btn_labels = "Ok", closeOnClickOutside = TRUE, width = NULL ) }) }) }