No reuse of output elements?

67 views
Skip to first unread message

Norman Packard

unread,
May 22, 2015, 7:28:26 PM5/22/15
to shiny-...@googlegroups.com

I have a header for use in each tab of a tabset, actually in each headerPanel of a pageWithSidebar within each tab.

I thought I could create a header with something like

output$header = renderUI({
...
  })

and call it with something like

headerPanel(uiOutput('header'),windowTitle="PDT")

for each of the headers in each of the tabs.

But... apparently this is not possible.  Apparently I cannot access uiOutput('header') multiple times.

If, however I define separate (identical) headers output$header1, output$header2, etc., I can access them with uiOutput('header1'), uiOutput('header2'), etc without a problem.

Seems crazy that I I have to repeat so much code with the multiple output$headers.  Probably I am not understanding something about the shiny relationship between R and javascript?



Dean Attali

unread,
May 22, 2015, 10:22:44 PM5/22/15
to shiny-...@googlegroups.com
I can understand why it's not possible to have multiple uiOutput('header'), because that literally creates an html tag with id header, and you can't have multiple tags with the same id.

I haven't tried this and it's not *ideal*, but would something like this work?

ui:
headerPanel(uiOutput('header1'), headerPanel(uiOutput('header2')

server:
commonHeader <- reactive({ ... })
output$header1
<- renderUI(commonHeader())
output$header2 <- renderUI(commonHeader())

That might not work at all, but it's the first thing I can think of



Joe Cheng

unread,
May 22, 2015, 10:28:03 PM5/22/15
to Dean Attali, shiny-...@googlegroups.com
I think you might be better off with a navbarPage, which has a header argument where you can put common elements. 

Sent from Outlook




--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/c09ae95c-f23a-4056-85fb-00b6b1f2da47%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dean Attali

unread,
May 22, 2015, 10:37:53 PM5/22/15
to Joe Cheng, shiny-...@googlegroups.com
If you want the header to go above rather than inside each tab, then yes, what Joe said. I might have misunderstood the original question but I thought you purposely tried putting the header under rather than above the tab. But simplifying it to his suggestion might be worth it

Joe Cheng

unread,
May 22, 2015, 10:52:03 PM5/22/15
to Dean Attali, shiny-...@googlegroups.com
I'm saying to use navbarPage instead of tabs, sorry if that wasn't clear. 

Sent from Outlook

jrdn...@gmail.com

unread,
May 28, 2015, 2:36:16 PM5/28/15
to shiny-...@googlegroups.com
Yes, it can get very repetitive.  You can avoid rewriting most of the code by doing all the work in a reactive statement so that in the output statements you just need to call the reactive.
Reply all
Reply to author
Forward
0 new messages