You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Client error console and inserted/removed UI elements #3944
With #3931, when dynamically adding UI to a running app, it seems that the matching IDs checks run on the entire app and flag stable input/output elements as duplicated.
library(shiny)
ui<- fluidPage(
actionButton('insertBtn', 'Insert'),
actionButton('removeBtn', 'Remove'),
tags$div(id='placeholder') #<< ui elements will be added here
)
server<-function(input, output) {
## keep track of elements inserted and not yet removedinserted<- c()
observeEvent(input$insertBtn, {
count<-input$insertBtn# give the inserted element a unique id so we can remove it laterid<- paste0('txt', count)
# push a new element in to the app
insertUI(
selector='#placeholder',
ui=tags$div(
tags$p(paste('Element number', count)),
id=id
)
)
inserted<<- c(inserted, id)
})
observeEvent(input$removeBtn, {
# pop last inserted element out of the app
removeUI(
selector= paste0('#', inserted[length(inserted)])
)
# and remove it from the list of inserted elementsinserted<<-inserted[-length(inserted)]
})
}
shinyApp(ui, server)
Similar behavior happens for insertTab() and removeTab().
library(shiny)
ui<- fluidPage(
actionButton('insertBtn', 'Insert'),
actionButton('removeBtn', 'Remove'),
tabsetPanel(
id="tabs",
tabPanel(
"Base",
"Base tab content. Other tabs will have their tab-specific text."
)
)
)
server<-function(input, output) {
## keep track of elements inserted and not yet removedinserted<- c()
observeEvent(input$insertBtn, {
count<-input$insertBtn# give the inserted element a unique id so we can remove it laternew_tab_title<- paste('Tab', count)
# push a new element in to the app
insertTab(
inputId="tabs",
tabPanel(
title=new_tab_title,
paste("Content for", new_tab_title)
)
)
inserted<<- c(inserted, new_tab_title)
})
observeEvent(input$removeBtn, {
# pop last inserted tab out of the app
removeTab(
inputId="tabs",
target=inserted[length(inserted)]
)
# and remove it from the list of inserted elementsinserted<<-inserted[-length(inserted)]
})
}
shinyApp(ui, server)
Activity
gadenbuie commentedon Nov 28, 2023
Similar behavior happens for
insertTab()andremoveTab().With client error console
Kapture.2023-11-28.at.12.06.49.mp4
shiny 1.8.0
Kapture.2023-11-28.at.12.06.08.mp4