Conditional tabPanel / tabsetPanel using renderUI and uiOutput

Showing 1-4 of 4 messages
Conditional tabPanel / tabsetPanel using renderUI and uiOutput Ben Sully 5/20/13 4:56 AM
Hi,

I've been trying to create a tabsetPanel which depends on some sidebar inputs, avoiding conditionalPanels, by using renderUI and a function to generate the tabPanel code. I gathered from a post last month that it might be possible but I can't seem to work it! What I have looks roughly like this:

server.R:

output$theTabset <- renderUI({
theOutputs <- returnOutputs(input1, input2, input3)
tabsetPanel(
theOutputs
 )
 })

ui.R:

mainPanel(
... 
uiOutput("theTabset"),
...
)

The output of returnOutputs() is a list with each element being the HTML for a tabPanel:

> returnOutputs(1,1,1)
[[1]]
[1] "<div class=\"tab-pane\" title=\"Panel 1\">\n  <div id=\"panel1Table\" class=\"shiny-html-output\"></div>\n  <div id=\"npanel1Plot\" class=\"shiny-plot-output\" style=\"width: 90% ; height: 500px\"></div>\n</div>"
attr(,"html")
[1] TRUE

[[2]]
[1] "<div class=\"tab-pane\" title=\"Panel 2\">\n  <div id=\"panel2Table\" class=\"shiny-html-output\"></div>\n  <div id=\"npanel1Plot\" class=\"shiny-plot-output\" style=\"width: 90% ; height: 500px\"></div>\n</div>"
attr(,"html")
[1] TRUE

and I've defined output$panel1Table, output$panel1Plot, etc. in server.R.

Everything except the tabsetPanel renders fine, but I get an error:
Error in if (!grepl(pattern, text)) return(text) : 
  argument is of length zero
and no tabsetPanel.

I've also tried changing output$theTabset to exclude the tabsetPanel( ) part in server.R and just return theOutputs, and having uiOutput("theTabset") inside a tabsetPanel in ui.R, but that was even less successful.

Does anyone know any solutions to this?

Cheers,
Ben
Re: Conditional tabPanel / tabsetPanel using renderUI and uiOutput Joe Cheng [RStudio] 5/20/13 9:03 AM
Try replacing tabsetPanel(theOutputs) with do.call(tabsetPanel, theOutputs).


--
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.
 
 

Re: Conditional tabPanel / tabsetPanel using renderUI and uiOutput Ben Sully 5/20/13 9:41 AM
That worked straight away! Thanks Joe. Is there an easy explanation for why do.call was needed in that situation?

Ben
Re: Conditional tabPanel / tabsetPanel using renderUI and uiOutput Joe Cheng [RStudio] 5/20/13 6:05 PM
tabsetPanel expects each tabPanel to be a separate argument. do.call takes a function and a list and invokes the function using the list's elements as arguments.

It's the difference between this (without do.call):

tabsetPanel(list(tabPanel(...), tabPanel(...), tabPanel(...)))

and this (with do.call):

tabsetPanel(tabPanel(...), tabPanel(...), tabPanel(...))