Conditional tabPanel

2,719 views
Skip to first unread message

Willi Fiebranz

unread,
Apr 22, 2013, 6:38:45 AM4/22/13
to shiny-...@googlegroups.com
Hi,

I would like to implement a conditional tab-construction, like

tabsetPanel(
    tabset("tab1", some widgets),
    conditionalPanel("input.something",
         uiOutput("some additional tabsets")
    )
)

I assume this is not possible yet, or is there a way?

Best,
WF

Joe Cheng

unread,
Apr 22, 2013, 1:51:37 PM4/22/13
to shiny-...@googlegroups.com
Right, not currently possible (without creating/destroying the entire tabsetPanel repeatedly, using uiOutput and renderUI).


--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Willi Fiebranz

unread,
Apr 23, 2013, 11:09:14 AM4/23/13
to shiny-...@googlegroups.com
Okay, thanks.

For future versions I would suggest, a singular tab-widget like

tabsetPanel(id = NULL, number.of.tabs = numeric(length = 1), names.of.tabs = character(length = number.of.tabs), tab.contents = list(uiOutput("tab1", ..., length = number.of.tabs)

I think something like this build in a reactive would allow for a more dynamic use of tabs.

Cheers!
WF

Willi Fiebranz

unread,
Apr 23, 2013, 11:11:04 AM4/23/13
to shiny-...@googlegroups.com
There is a closing bracket missing behind "tab1", sorry

Joe Cheng

unread,
Apr 23, 2013, 12:27:05 PM4/23/13
to shiny-...@googlegroups.com
Wait, maybe I misunderstood. Are you trying to have tabs come and go, or is the number of tabs fixed? Your initial question made me think the former, but your code snippet looks like the latter.

Willi Fiebranz

unread,
Apr 24, 2013, 3:51:30 AM4/24/13
to shiny-...@googlegroups.com
Come and go.

Currently I can only write a reactive function that generates me a complete tabsetPanels based on different conditions. This becomes very unpractical at some level of complexity.

I think a simple approach for a future version would be to make conditionalPanel(s) valid to wrap around tabPanels within a tabsetPanel like:

tabsetPanel(
   tabPanel("Summary All", uiOutput("somestuff_all")),
   conditionalPanel(condition = "input.cond_a.",
      tabPanel("Summary A", uiOutput("somestuff_a"))
   ),
   conditionalPanel(condition = "input.cond_b.",
      tabPanel("Summary B", uiOutput("somestuff_b"))
   )
)

Joe Cheng

unread,
Apr 24, 2013, 6:26:08 PM4/24/13
to shiny-...@googlegroups.com
OK, thanks for the feedback.

cassandra....@ventirisk.com

unread,
Jul 26, 2013, 10:19:31 AM7/26/13
to shiny-...@googlegroups.com
Can you show example code of creating/destroying the tabsetPanel?

Joe Cheng

unread,
Jul 29, 2013, 8:02:36 PM7/29/13
to shiny-...@googlegroups.com
You have uiOutput("tabsets") in your ui.R, and then in your server.R something like:

output$tabsets <- renderUI({
  tabs <- ...
  do.call(tabsetPanel, c("tabpanel", tabs))
})

where "..." is replaced with whatever logic you use to create a list of tabPanel() objects. If that logic uses reactive values/expressions then the entire tabset panel (which we're calling "tabpanel" here) will be replaced each time the reactive dependencies change.


Fazel Tabassum

unread,
Feb 22, 2017, 7:27:37 AM2/22/17
to Shiny - Web Framework for R
Is there a way where a tab is only displayed if a certain condition is met ?
Something along the lines of these :

ui<- fluidpage(
tabsetPanel(
  id = "panels",
  tabPanel("tab1",
           #someoutput
           )
  ,
  conditionalPanel("somecondition", tabPanel(
    id = "tab2",
    #someoutput
  ))
)
)
Reply all
Reply to author
Forward
0 new messages