【问题标题】:Use an actionbutton to go to another tab使用操作按钮转到另一个选项卡
【发布时间】:2018-04-04 17:16:59
【问题描述】:

我有以下闪亮的应用程序:

ui <- fluidPage(
  tabsetPanel(
    tabPanel("Tab 1",
      actionButton("switch_tab", "Go to the second tab")
    ),
    tabPanel("Tab 2", "there!"),
    tabPanel("Tab 3", "there!"))

)

server <- function(input, output, session) {

  observeEvent(input$switch_tab, {
    updateTabsetPanel(session, "inTabset",
                      selected = "Tab 3")
  })

}
shinyApp(ui = ui, server = server)

当我单击“转到第二个选项卡”按钮时,它基本上应该切换选项卡。但是它不起作用。

对我可能忽略的内容有任何反馈吗?

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    你需要在tabsetpanel中添加id

    library(shiny)
    ui <- fluidPage(
            tabsetPanel(
                    id="inTabset",
                    tabPanel("Tab 1",actionButton("switch_tab", "Go to the third tab")
                    ),
                    tabPanel("Tab 2", "there!"),
                    tabPanel("Tab 3", "there!"))
    
    )
    
    server <- function(input, output, session) {
    
            observeEvent(input$switch_tab, {
                    updateTabsetPanel(session, "inTabset",selected = "Tab 3")
            })
    
    }
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-18
      • 2013-02-27
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 2015-09-18
      • 1970-01-01
      相关资源
      最近更新 更多