访问 R shiny 中嵌套选项卡集和选项卡面板中操作 link 的会话

Access sessions for action link in Nested Tabset and Tabpanels in R shiny

我在这里尝试在选项卡之间创建一个操作链接,但我在其中有许多嵌套选项卡,并且由于我是从嵌套选项卡本身而不是主会话调用链接,所以我无法放置id 正确。

我已经研究过这个问题:,但这只适用于主会话。

这是我的可重现代码的一部分:

     ui <- fluidPage(
 navbarPage(id = "Navbar",
 tabPanel("About",..
 actionLink("link_to_overview", "Let's start with the Overview!"), <--- This works
 ),
 
 tabPanel("Overview",
          tabsetPanel(id = "Tab_ov",
          tabPanel("Flights",..
          actionLink("link_to_airlines", "Let's go to the Airlines!"),<--- This doesn't work
                                    
          ),
          
          tabPanel("Airlines",..
          actionLink("link_to_domestic_stats", "Let's go to the Domestic!") <--- This doesn't work
          ),
          )),
          

    tabPanel("Statistics",
          tabsetPanel(id = "stats_tab",
          tabPanel("Domestic",..
          ),
          
          tabPanel("International",..),
          ))
          ))
          
server <-     function(input, output, session) {
observeEvent(input$link_to_overview, {
    newvalue <- "Overview"
    updateTabItems(session, "Navbar", newvalue)
  })
  
observeEvent(input$link_to_airlines, {
    updateTabsetPanel(session, inputId = 'Flights', selected = 'Tab_ov')
    updateTabsetPanel(session, inputId = 'Overview', selected = 'Airlines')
  })
  
observeEvent(input$link_to_domestic_stats, {
    updateTabsetPanel(session, inputId = 'Overview', selected = 'Statistics')
    updateTabsetPanel(session, inputId = 'stats_tab', selected = 'Domestic')
  })
  
  }

试试这个: 图书馆(闪亮) 图书馆(整洁宇宙)

ui <- fluidPage(navbarPage(
    id = "Navbar",
    tabPanel(
        "About",
        actionLink("link_to_overview", "Let's start with the Overview!")
    ),
    
    tabPanel("Overview",
             tabsetPanel(
                 tabPanel(
                     "Flights",
                     value = 'flights',
                     actionLink("link_to_airlines", "Let's go to the Airlines!")
                     
                     
                 ),
                 
                 tabPanel(
                     "Airlines",
                     value = 'airlines',
                     actionLink("link_to_domestic_stats", "Let's go to the Domestic!") 
                 ), id = "Tab_ov"
             ),value = 'ovview'),
    
    
    tabPanel(
        "Statistics",
        tabsetPanel(
                    tabPanel("Domestic", value = 'domestic'),
                    
                    tabPanel("International", ''),
                    id = "stats_tab")
    )
))

server <-     function(input, output, session) {
    observeEvent(input$link_to_overview, {
        
        updateTabsetPanel(session, "Navbar", 'ovview')
    })
    
    observeEvent(input$link_to_airlines, {
        updateTabsetPanel(session, inputId = 'Tab_ov', selected = 'airlines')
    })
    
    observeEvent(input$link_to_domestic_stats, {
        updateTabsetPanel(session, inputId = 'Navbar', selected = 'Statistics')
        updateTabsetPanel(session, inputId = 'stats_tab', selected = 'domestic')
    })
    
}

shinyApp(ui, server)