Hi all,
With some effort, I was able to bookmark reactive tabs as shown. But facing few more challenges
library(shiny)
library(DT)
init.choices <- c("Choose From List or Type New Value"="")
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")),
tabPanel(
"tab1", selectizeInput("foo", NULL,
choices=init.choices,
multiple=FALSE,
options=list(create=TRUE)),
selectizeInput("foo1", NULL,
choices=init.choices,
multiple=FALSE,
options=list(create=TRUE)),
plotOutput("d")
))
)
)
}
server <- function(input, output, session) {
# Create container to house tabs selected in a session
values <- reactiveValues(n = numeric())
insertTabCustom = function(id) {
insertTab(inputId = "tabs",
tabPanel(paste0("tabs",id), "This a dynamically-added tab"),
target = "Summary",select = TRUE
)
}
observe({
updateSelectizeInput(session, "foo", choices=c(init.choices, c(1,2,3)), server=TRUE)
})
observe({
updateSelectizeInput(session, "foo1", choices = c(7,8,as.numeric(input$foo)+1), selected = as.numeric(input$foo)+1, server=TRUE)
})
observe({
# Trigger this observer every time an input changes
reactiveValuesToList(input)
# reactiveValuesToList(output)
session$doBookmark()
})
onBookmarked(function(url) {
updateQueryString(url)
})
output$tab <- renderDataTable({
datatable(iris,selection = 'single')
})
observeEvent(input$tab_rows_selected, {
values$n <- input$tab_rows_selected
updateSelectizeInput(session, "foo", choices=c(init.choices, c(1,2,3,values$n)), selected = values$n, server=TRUE)
updateSelectizeInput(session, "foo1", choices = c(7,8,values$n+1), selected = values$n+1, server=TRUE)
updateTabsetPanel(session, inputId = "tabs", selected = "tab1")
})
onRestored(function(state) {
# for (i in state$values$n) insertTabCustom(i)
# updateTabsetPanel(session, inputId = "tabs", selected = paste0("tabs",state$values$n[-1]))
updateSelectizeInput(session, "foo", selected=state$values$n, choices=c(init.choices, c(1,2,3), state$values$n), server=TRUE)
updateSelectizeInput(session, "foo1", selected=state$values$n+1, choices=c(init.choices, c(7,8), state$values$n+1), server=TRUE)
updateSelectizeInput(session, "foo", selected=state$input$tab_rows_selected, choices=c(init.choices, c(1,2,3), state$input$tab_rows_selected), server=TRUE)
updateSelectizeInput(session, "foo1", selected=state$input$tab_rows_selected+1, choices=c(init.choices, c(7,8), state$input$tab_rows_selected+1), server=TRUE)
})
output$d <- renderPlot({
plot(input$foo,input$foo1)
})
}
enableBookmarking("server")
shinyApp(ui, server)
Below is what is happenig
- Open the app
- Click on any row (Say 2)
- You are directed to other tab (with first filter as 2 and second filter as 3)
- Now copy the url
- Paste the url in another tab.
- Now same state opens (with first filter as 2 and second filter as 3) --- This is perfectly right
Now,
7. Close tab that you opened before(6 point). I mean come to initial app
8. Change the first filter (Say 3)
9. Second filter changes to 4---- This is perfectly right
This is where problem rises
10. Now copy this url (with first filter as 3 and second filter as 4)
11. If you paste this url in another tab, the state where first filter as 2 and second filter as 3, opens up---- This is wrong. I need to have first filter as 3 and second filter as 4
Hope this is clear. Can anyone help me