I am trying to navigate to the next tab by clicking on a link nested in a datatable.
This works fine at first using Shiny.bindAll
. Here you can find an explanation from Joe Cheng regarding the use of the function.
However, when the datatable is re-rendered by filtering the input data via the selectInput
the binding is lost when switching back from 2 to 1:
library(shiny)
library(DT)
library(dplyr)
ui <- fluidPage(tabsetPanel(
id = "panels",
tabPanel("A",
selectInput("sel", "Select", choices = c(1,2)),
DTOutput("tab")),
tabPanel("B",
h3("Some information"),
tags$li("Item 1"),
tags$li("Item 2"),
actionLink("goToTabPanelA", "goToTabPanelA")
)
))
server <- function(input, output, session) {
DF <- data.frame(a = c(1,2),
b = c(HTML('<a id="goToTabPanelB1" class="action-button" href="#">goToTabPanelB1</a>'),
HTML('<a id="goToTabPanelB2" class="action-button" href="#">goToTabPanelB2</a>')))
output$tab <- renderDataTable({
datatable(
DF %>% filter(a %in% input$sel),
escape = FALSE,
selection = 'none',
options = list(
preDrawCallback = JS('function() { Shiny.unbindAll(this.api().table().node()); }'),
drawCallback = JS('function() { Shiny.bindAll(this.api().table().node()); } ')
)
)
})
observeEvent(c(input$goToTabPanelB1, input$goToTabPanelB2), {
updateTabsetPanel(session, "panels", "B")
})
observeEvent(input$goToTabPanelA, {
updateTabsetPanel(session, "panels", "A")
})
}
shinyApp(ui, server)