isolate input in a module shiny when using insert ui

I'd like to create several ui which use an input parameter. The problem is that the new UI created is still reacting to the input even when I put an isolate().

The right behaviour would give a custom UI created and isolated from the new inputs coming from the selectInput().


In this screen for instance, I've inserted two UI. If I click on my selectbox to add or remove a year, the UIs are still reacting.

library(shiny)
customplotUI <- function(id){
  ns <- NS(id)
  fluidPage(
    sidebarPanel(id=ns("sidebarpanel"),
                 actionButton(ns("add"),label = "Add"),
                 selectInput(inputId=ns("years"),label="Year :", choices = c(2019,2020),selected = 2019, multiple = TRUE)),
    mainPanel(div(id=ns("placeholder"))
              )
  )
}
customplot <- function(input,output,session){
  ns <- session$ns
  
  output$res <- renderPrint({
    data <- data.frame(year=c(2019,2020),value=c("mtcars2019","mtcars2020"))
    data[data$year %in% input$years,]})
  
  
  ctn <- reactiveVal(0)
  
  Id <- reactive({
    function(id){
      paste0(id, ctn())
    }
  })
  IdNS <- reactive({
    function(id){
      ns(paste0(id, ctn()))
    }
  })
  observeEvent(input$add, {
    ctn(ctn() + 1)
    print(Id()('div'))
    
    insertUI(
      selector = paste0('#', ns('placeholder')),
      ui = div(
        id = Id()('div'),
        verbatimTextOutput(IdNS()('chart'))
        )
      )
    id <- Id()('chart')
      output[[id]] <- renderPrint({
        data <- data.frame(year=c(2019,2020),value=c("mtcars2019","mtcars2020"))
        #data[data$year %in% isolate(input$years),]
        data[data$year %in% input$years,]
      })
  })
  
}

ui <- fluidPage(
  customplotUI(id="customplot")
)
server <- function(input, output, session){
  callModule(customplot,id="customplot",session=session)
}

shinyApp(ui, server)

The problem has been solved on stackoverflow.
Here is the answer