0

以下のアプリケーションは、DT テーブルで選択された行と選択されたタブに基づいて URL を更新しています。しかし、ユーザーが別のタブに URL をコピーして貼り付けると、特定のタブが開かれるのではなく、デフォルトのページが開かれます (url : http://127.0.0.1:XXXX/?tabs=tabs2 ) 。

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"),
              target = "Summary",select = TRUE
                
    )
  })
  

}


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

0 に答える 0