0

I am using a conditionalPanel option to choose the tabs to show based on a selectInput.

When I select "Four" I should have four tabs including tab2 which should not be visible on the selection of "Three".

The issue is that with the selection of "Four" option the tab2 is not visible in line with others.

Is there a way to use conditionalPanel and make tab2 appear between tab1 and tab3 at the selection of "Four" and not "Three"?

  library(shiny)
  library(shinydashboard)

  ui <- dashboardPage(
        dashboardHeader(),
        dashboardSidebar(
        sidebarMenu(

        selectInput(
       inputId="selectTabs",
       label=" Choose Number of TABS", selected = NULL,
        choices=c( "Four", "Three" )),
      menuItem("TABS Number", tabName = "Tabs", icon = icon("object-ungroup"))

  )
 ),
 dashboardBody(
  tabItem(tabName = "Tabs",

        fluidRow(
          column(width=3, 

                 box(

                   title="Search ",
                   solidHeader=TRUE,
                   collapsible=TRUE,
                   width=NULL,

                   textInput("textSearch", " Search ",  '', placeholder = "Type keyword/statement"),


                   submitButton("Search")

                 )
          ),
          column( width=9,
                  tabBox(
                    width="100%",


                    tabPanel("tab1",
                             htmlOutput("search1")
                    ),

                    conditionalPanel("input.selectTabs === 'Four'",
                    tabPanel("tab2",
                             htmlOutput("search2")
                    )),
                    tabPanel("tab3",
                             htmlOutput("search3")
                    ),


                    tabPanel("tab4",
                             htmlOutput("search4")
                    )




                  )
          )

          )
       )
     )
   )

  server <- function(input, output) {}

 shinyApp(ui, server)

As an update from the suggestion by @annhan concerning the possible duplication, here is my update code which gives me undesirable output in that I have two rows of tabapanels instead of one dynamic one.

 library(shiny)
 library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
  sidebarMenu(

  selectInput(
    inputId="selectTabs",
    label=" Choose Number of TABS", selected = NULL,
    choices=c( "Four", "Three" )),
  menuItem("TABS Number", tabName = "Tabs", icon = icon("object-ungroup"))

 )
),
dashboardBody(

tabItem(tabName = "Tabs",

        fluidRow(
          column(width=3, 

                 box(

                   title="Search ",
                   solidHeader=TRUE,
                   collapsible=TRUE,
                   width=NULL,

                   textInput("textSearch", " Search ",  '', placeholder = "Type keyword/statement"),


                   submitButton("Search")

                 )
          ),

          column( width=9,

                  conditionalPanel("input.selectTabs == 'Four'",
                  tabBox(
                    width="100%",


                    tabPanel("tab1", value=1,
                             htmlOutput("search1")
                    ),


                    tabPanel("tab2", value=2,
                             htmlOutput("search2")
                    ),
                    tabPanel("tab3", value=3,
                             htmlOutput("search3")
                    ),


                    tabPanel("tab4", value=4,
                             htmlOutput("search4")
                    )




                  )),



                  conditionalPanel("input.selectTabs == 'Three' && input.selectTabs != 'Four'",
                                   tabBox(
                                     width="100%",


                                     tabPanel("tab1", value=5,
                                              htmlOutput("search1")
                                     ),



                                     tabPanel("tab3", value=7,
                                              htmlOutput("search3")
                                     ),


                                     tabPanel("tab4", value=8,
                                              htmlOutput("search4")
                                     )                                                                         


                                   ))                     

          )))))                


    server <- function(input, output) {}

   shinyApp(ui, server)
R noob
  • 495
  • 3
  • 20
  • Possible duplicate of [Add dynamic tabs in shiny dashboard using conditional panel](https://stackoverflow.com/questions/38931578/add-dynamic-tabs-in-shiny-dashboard-using-conditional-panel) – annhak Nov 09 '18 at 13:15
  • @annhak possibly it is a duplicate but if you see the update it gives me two columns of tabpanels. Is there something I am doing wrong? – R noob Nov 13 '18 at 10:13

0 Answers0