bookmarking multiple reactive tabs not working in shiny

Hi all,

Really appreciate if anyone can help me here since I am stuck after researching on this everywhere.

The below application is updating the url based on row selected in the DT table and the selected tab. But what happens is, when the user copy paste the url in another tab, it is not opening the specific tab, instead it is opening the default page (url : http://127.0.0.1:XXXX/?tabs=tabs3).

I mean reactive tabs are not working.

Please follow these steps for the reference

  1. Click on any row(say 3) on DT table(Summary tab)
  2. An new tab3 opens (that is fine) which prints 3
  3. Copy the url now (tab3 url)
  4. Paste this url to another tab (Now it returns to Summary tab only and not tab3).

Am I doing something wrong here?

library(shiny)
library(DT)

ui <- function(request) {
  shinyUI(navbarPage(
    "Title", id = "inTabset", selected = "Summary",
    tabsetPanel(id = "tabs",
                # tabPanel(
                #   "Readme",tags$head(tags$link(rel = "stylesheet", type="text/css", href="style.css"))
                # ),
                tabPanel(
                  "Summary",
                  dataTableOutput("tab")))
  )
  )
}

server <- function(input, output, session) {
  # Make sure you only bookmark the tabsetPanel
  setBookmarkExclude(isolate(names(input)[names(input) != "tabs"]))
  
  # Every time the tab changes, store the app state as URL bookmark
  observeEvent(input$tabs, {
    session$doBookmark()
  })
  
  # Set callback that stores the app state in the URL
  onBookmarked(function(url) {
    updateQueryString(paste0("?tabs=", input$tabs), mode = "replace")
  })
  # Set callback to restore the app state from the URL
  onRestore(function(state) {
    updateTabsetPanel(inputId = "tabs", selected = getQueryString()[["tabs"]])
  })
  
  output$tab <- renderDataTable({
    datatable(iris,selection = 'single')
  })
  
  observeEvent(input$tab_rows_selected, {
    insertTab(inputId = "tabs",
              tabPanel(paste0("tabs",input$tab_rows_selected), "This a dynamically-added tab",htmlOutput("sd")),
              target = "Summary",select = TRUE
              
    )
  })
  
  output$sd <- renderUI({
    as.character(input$tab_rows_selected)
  })
  
  
}


enableBookmarking("url")
shinyApp(ui, server)

This topic was automatically closed 54 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.