我有以下闪亮的应用程序:
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)
Run Code Online (Sandbox Code Playgroud)
当我单击“转到第二个选项卡”按钮时,它基本上应该切换选项卡。然而,它不起作用。
关于我可能忽略的任何反馈?
您需要添加id到 tabsetpanel
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)
Run Code Online (Sandbox Code Playgroud)