Having trouble deleting tabs that have been newly created in Shiny.
Scenario:
- Add new tab "A"
- Add new tab "B"
- Click delete on tab B - doesn't delete
- Select tab A, click delete it works
I feel its something to do with ids, stumped with the logic.
Thanks in advance.
library(shiny)
library(shinyjs)
ui <- fluidPage(
useShinyjs(),
navbarPage(title = "Test", id="tabs",
tabPanel("Home",
sidebarPanel(
selectInput("testlist", "Select test:",
list("A", "B", "C")),
actionButton("append", "New tab")),
mainPanel()
)
)
)
server <- function(input, output, session) {
tabnamesinput<-reactive({
input$testlist
})
observeEvent(input$append,{
id<-paste0(tabnamesinput())
appendTab(inputId = "tabs",
tabPanel(id,
sidebarPanel(
actionButton("remove", "Delete")
)
)
)
})
observeEvent(input$remove,{
removeTab(inputId = "tabs", target = input$tabs)
})
}
shinyApp(ui, server)
