Is there any way for an actionButton() to navigate to another tab within a R Shiny application?

老子叫甜甜 提交于 2020-01-14 14:27:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!