Home > OS >  Navigate through tabItems using actionButton()
Navigate through tabItems using actionButton()

Time:11-29

I am using the actionButton() to move from the 1st tabItem() to the 2nd but while it seems to work I remain on the first tabItem().

## app.R ##
library(shiny)
library(shinydashboard)



ui <- dashboardPage(
  dashboardHeader(
   
    
  ),
  dashboardSidebar(
    collapsed = TRUE,
    sidebarMenu(
      id="inTabset",
      menuItem("Workspace", tabName = "workspace", icon = icon("upload")),
      
      menuItemOutput("tab2")
      
      
      
      
    )
  ),
  dashboardBody(
    
    tabItems(
      # First tab content
      tabItem(tabName = "workspace",
              fluidRow(
              
                         
                        
                           
                           textInput("name", "", value = "Process model", placeholder = NULL),
                           actionButton("nextt","Next", icon("paper-plane") 
                                        )

                         
                       )
                       
                )
                
      ),
      
     
      tabItem(
        tabName = "Process model",
        
    )
  )

)

server <- function(input, output,session) {
  output$tab2 <- renderMenu({
    menuItem(text = input$name, tabName = "Process model", icon = icon("diagram-project"))  
  })
  observeEvent(input$nextt, {
    updateTabItems(session, "inTabset", selected = "Process model")
  })
  
  
  
  output$tabtitle <- renderText({
    if (input$name == "") {
      "Process model"
    } else {
      paste(input$name)
    }
  })
  
  observeEvent(input$nextt, {
    updateTabItems(session, "inTabset", selected = "Process model")
  })
  
  
  
}


shinyApp(ui, server) 

CodePudding user response:

While the name of the tab may have spaces, its value should not. This should now work i.e. Process_model:

## app.R ##
library(shiny)
library(shinydashboard)



ui <- dashboardPage(
  dashboardHeader(
    
    
  ),
  dashboardSidebar(
    collapsed = TRUE,
    sidebarMenu(
      id="inTabset",
      menuItem("Workspace", tabName = "workspace", icon = icon("upload")),
      
      menuItemOutput("tab2")
      
      
      
      
    )
  ),
  dashboardBody(
    
    tabItems(
      # First tab content
      tabItem(tabName = "workspace",
              fluidRow(
                
                
                
                
                textInput("name", "", value = "Process model", placeholder = NULL),
                actionButton("nextt","Next", icon("paper-plane") 
                )
                
                
              )
              
      )
      
    ,
    
    
    tabItem(
      tabName = "Process_model",
      
    ))
  )
  
)

server <- function(input, output,session) {
  output$tab2 <- renderMenu({
    menuItem(text = input$name, tabName = "Process_model", icon = icon("diagram-project"))  
  })
  observeEvent(input$nextt, {
    updateTabItems(session, "inTabset", selected = "Process_model")
  })
  
  
  
  output$tabtitle <- renderText({
    if (input$name == "") {
      "Process model"
    } else {
      paste(input$name)
    }
  })
  
  observeEvent(input$nextt, {
    updateTabItems(session, "inTabset", selected = "Process_model")
  })
  
  
  
}


shinyApp(ui, server) 
  • Related