问题
I have multiple tabs within my R Shiny app and haven't discovered a way to have my action button navigate to another tab.
The first tab ends with a "submit info" action button, and the goal is to have the "results" tab open after the user submits. If anyone might have some pseudo code that could make this happen, anything would be extremely helpful.
回答1:
Hi you can use updateTabsetPanel
to do that, you have to put an id to your tabsetPanel
(if you use a tabsetPanel
) and add session
to your server function :
library("shiny")
ui <- fluidPage(
tabsetPanel(
id = "tabs",
tabPanel(
title = "params",
actionButton(inputId = "submitInfo", label = "submit info")
),
tabPanel(
title = "result",
"result"
)
)
)
server <- function(input, output, session){
observeEvent(input$submitInfo, {
updateTabsetPanel(session = session, inputId = "tabs", selected = "result")
})
}
shinyApp(ui = ui, server = server)
If you use a navbarPage
or shinydashboard
it works the same way
来源:https://stackoverflow.com/questions/38706965/is-there-any-way-for-an-actionbutton-to-navigate-to-another-tab-within-a-r-shi