Dynamic tab when clicked on rows of data table

Hi all,

Is there a way to dynamically create a tabs(with cancel symbol) when clicked on rows of datatable. For example, when 1st row is clicked then tab name tab_1 is created , then when 2nd row is clicked, then
tab name tab_2 is created and so on. But we should be able to close these tabs with small cancel symbol

library(shiny)
library(readxl)
library(dplyr)
library(xtable)
library(shinyWidgets) ## for picker input
library(shinydashboard) 
library(DT)
library(tidyverse)
library(shinycssloaders)
library(plotly)
library(htmlwidgets)
library(sparkline)
library(data.table)
require(reshape2)
library(glue)


ui <- shinyUI(navbarPage(

  "Title",id = "inTabset",selected = "Summary",
    tabPanel(
    "Read me",tags$head(tags$link(rel = "stylesheet", type="text/css", href="style.css"))
  ),
  tabPanel(
    "Summary",uiOutput("sel"),
    DT::dataTableOutput("tab")), 
  tabPanel("Topics",
           column(width = 1, uiOutput("wd")),
           column(offset = 0, width = 1, uiOutput("cou")),
           column(offset = 0, width = 2, uiOutput("app")),
           column(offset = 0, width = 2, uiOutput("ver")),
           column(offset = 0, width = 2, uiOutput("tag")),
           column(offset = 0, width = 1, uiOutput("nt")),
           column(offset = 0, width = 2, uiOutput("rat")),
           column(offset = 0, width = 2),
           br(),br(),br(),
           DT::dataTableOutput("expe_table"),
           br(),br(),br()
           
  ),
  uiOutput("rec_tab")
)
)

server <- function(input, output, session) {

  output$tab <- DT::renderDataTable({
    datatable(iris,selection = 'single')
  })
  
  observeEvent(input$tab_rows_selected, {
    print(input$tab_rows_selected)
  })
 
  
  observeEvent(input$tab_rows_selected, {
    insertTab(inputId = paste0("tabs",input$tab_rows_selected),
              tabPanel("Dynamic", "This a dynamically-added tab"),
              target = "Bar"
    )
  })
  
}

shinyApp(ui, server)

Small cancel button as below

![image|243x48](upload://kVpgS8wJJ5cnVw2oy16oEMuZMG9.png)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.