Hi @viciously. Your code problem is due to the o is not a reactive valuable. So, you may change your code like this.
options(shiny.reactlog = TRUE)
library(shiny)
library(reactlog)
library(shinydashboard)
library(rlist)
ui <- dashboardPage(
dashboardHeader(title = "test"),
dashboardSidebar(),
dashboardBody(
uiOutput("def"),
uiOutput("def2")
)
)
server <- function(input, output, session) {
o <- reactiveVal(list())
output$def <- renderUI({
fluidPage(fluidRow(
numericInput("numberOfButtons", "provide number of buttons", value = 10, min = 1, max = 1000)
))
})
output$def2 <- renderUI({
req(input$numberOfButtons > 0)
fluidPage(fluidRow(
lapply(1:input$numberOfButtons, function(x){
actionButton(inputId = paste0("button_", x), label = paste0("button_", x))
})
))
})
observe({
req(input$numberOfButtons > 0)
isolate({
lapply(o(), function(x){x$destroy()})
inputBtn <- paste0("button_", 1:input$numberOfButtons)
o(lapply(inputBtn, function(x){
observeEvent(input[[x]],{
showModal(modalDialog(
title = as.character(x),
paste(x,"!"),
easyClose = TRUE
))
})
}))
})
})
}
shinyApp(ui, server)
But if your question is to completely destroy the observer and it seems the destroy function didn't help. The destroy function just to stop the observer from being triggered again by the reactive. You can test it by adding the following code and increase the numberOfButtons over 10 to destroy the a observer, but it still exists in the reactlog just cannot trigger by reactive anymore.
a <- observeEvent(input$numberOfButtons,{
if(input$numberOfButtons <= 10) {
cat("Test", file = stderr())
} else {
a$destroy()
}
})