How do I make the tabs reactive from selectInput

Instead of having the two tab selections on the side I want to put them into a selectInput drop down menu. What would be the best way to do this?

ui <- dashboardPage(
  dashboardHeader(title = "Human Trafficking"),
  
  dashboardSidebar(
  sidebarMenu(
    menuItem(tabName = "victim", "Victim"),
    selectInput("HumanTrafficking", "Choose a trafficking type: ", list("Victim", "Trafficker")),
    menuItem(tabName = "trafficker", "Trafficker", badgeLabel = "new", badgeColor = "green")
  )
)

Hi,

I don't know why exactly you want this, but I did come up with a way to do it, yet I'm not sure it's the most elegant solution :slight_smile:

library(shiny)
library(shinydashboard)
library(shinyjs)

ui <- dashboardPage(
  dashboardHeader(title = "Human Trafficking"),
  
  dashboardSidebar(
    sidebarMenu(
      selectInput("HumanTrafficking", "Choose a trafficking type: ", list("Victim", "Trafficker"))
    )
  ),
  dashboardBody(useShinyjs(),
      tags$div(id = "VictimTab",
               tags$h1("VictimTab")
              ),
      tags$div(id = "TraffickerTab",
               tags$h1("Trafficker")
               )
  )
)

server <- function(input, output, session) {
 
  observeEvent(input$HumanTrafficking, {
    if(input$HumanTrafficking == "Victim"){
      showElement("VictimTab")
      hideElement("TraffickerTab")
    } else {
      hideElement("VictimTab")
      showElement("TraffickerTab")
    }
  })


}

shinyApp(ui, server)

Grtz,
PJ

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.