【问题标题】:Access sessions for action link in Nested Tabset and Tabpanels in R shiny访问会话以获取嵌套选项卡集中的操作链接和 R Shiny 中的选项卡面板
【发布时间】:2021-08-22 15:38:04
【问题描述】:

在这里我试图在选项卡之间创建一个动作链接,但我有许多嵌套选项卡,因为我是从嵌套选项卡本身而不是主会话调用链接,所以我无法放置 id正确。

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

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

     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')
  })
  
  }

【问题讨论】:

    标签: r shiny shinydashboard shiny-server rshiny


    【解决方案1】:

    试试这个: 图书馆(闪亮) 图书馆(tidyverse)

    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)
    

    【讨论】:

    • 谢谢!它完美地工作!你为我节省了很多时间来解决这个问题!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-11
    • 2023-03-25
    • 1970-01-01
    • 2017-02-17
    相关资源
    最近更新 更多