Following a previous question https://stackoverflow.com/a/60072174/12812645 , I am trying to nest dynamic accordions in a shiny app.
As you can see on the example below, nothing happen when clicking on the "+" actionLink (created by insertUI). I tried to debug inserting a browser() inside the observeEvent function of this action Link and the R console print the following message in response to insertUI:
function ()
{
.callbacks$remove(id)
}
<environment: 0x00000000138245b8>
What does this mean ?
here is the code of the shiny app I would like to fix :
library(shiny)
library(dqshiny)
selectorUI <- function(id){
ns = NS(id)
tags$div(
fluidRow(
column(6, uiOutput(ns('new_ui')))
),
id = paste0('ui', id)
)
}
selectorServer <- function(input, output, session){
ns = session$ns
output$new_ui <- render_dq_box_group({
dq_accordion(ns("foo"),
titles = ns("input"),
contents = list(textInput(inputId = ns("txt"),
label = "")),
bg_color = NULL,
options = list(animate = 200, collapsible = TRUE),
icons = c(open = "hand-point-down", closed = "hand-point-right")
)
})
}
ui = fluidPage(
fluidRow(
actionButton("add", "+"),
selectorUI(1),
selectorUI(2),
selectorUI(3),
tags$div(id = 'placeholder'),
actionButton("delete", "-")
)
)
server = function(input, output) {
callModule(selectorServer, 1)
callModule(selectorServer, 2)
callModule(selectorServer, 3)
counter <- reactiveValues(value = 3) # number of inputs already present
observeEvent(input$add, {
counter$value <- counter$value + 1
insertUI(
selector = "#placeholder",
ui = selectorUI(counter$value)
)
callModule(selectorServer, counter$value)
insertUI(
selector = "#placeholder",
ui = tagList(
actionLink(paste0("add",counter$value), "+"),
tags$div(id = paste0('placeholder',counter$value))
)
)
})
observeEvent(input$delete, {
removeUI(
selector = paste0("#ui", counter$value)
)
counter$value <- counter$value - 1
})
observeEvent(input[[paste0("add",counter$value)]], {
counter$value <- counter$value + 1
insertUI(
selector = paste0("#placeholder",counter$value),
ui = selectorUI(counter$value)
)
callModule(selectorServer, counter$value)
})
}
shinyApp(ui, server)
Edit : after several tries I can't figure it out :-/ Does anyone have any idea where I might be looking? Thanks