Hi all,
I need your help in capturing the url.
In the below example, I am updating the url based in tabs selected. Suppose when the user clicks on row2 of the DT table, tab2 is opened(url is also updated accordingly) . But when we copy the url (say : http://127.0.0.1:XXXX/?tabs=tabs2), I do not get tha specfic state of the app, instead I get the default page.
Can you help me here. I need to have specific state of app when we paste the url
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)