App with multiple html Templates

665 views
Skip to first unread message

David Croushore

unread,
Mar 28, 2017, 1:13:28 PM3/28/17
to Shiny - Web Framework for R
Hi - 

I'm building a multi-page shiny app and have run into a bit of a problem. We wanted to use the shinyUI to define the tabs, then include custom HTML from our design team within each tab.

pseudocode:

shinyUI(
  navbarPage(
    'Project', 
    header = HTML('<meta charset="utf-8">
                   <meta http-equiv="X-UA-Compatible" content="IE=edge">
                   <meta name="viewport" content="width=device-width, initial-scale=1">'
    ),
    theme = 'css/style.css',
    tabPanel('Summary',
             htmlTemplate("summary.html")
    ),
    tabPanel('Tab2',
             htmlTemplate("tab2.html")
    )
  )
 )

If I include only the summary tab, everything renders properly. When I add the second, nothing renders from the server, though the UI elements appear as expected on each tab. I tried using includeHTML() instead of htmlTemplate() but then my R code just appears as is, and doesn't evaluate to anything.

Can anyone point me in the right direction?



Bárbara Borges

unread,
Mar 28, 2017, 1:55:53 PM3/28/17
to Shiny - Web Framework for R
What do you mean with "nothing renders from the server"? Can you include a minimal example, if you can produce one? Or give detailed instructions how to repro it?

David Croushore

unread,
Mar 28, 2017, 2:06:58 PM3/28/17
to Shiny - Web Framework for R


server <- shinyServer(function(input, output) {
  output$today <- renderText({Sys.Date()})
  output$tomorrow <- renderText({Sys.Date() + 1})
})

tab1.html
<!--/ Content -->
<div class="container-fluid" id="mainContent">
    <div class="row">
        <div class="col-lg-7 col-md-7">
            <h2>Business Summary</h2>
            <div class="col-lg-3 col-md-3 col-sm-12 col1">
                <div class="col-lg-12 col-md-12 col-sm-4 col-xs-12 num">
                  Today is: {{ textOutput('today')}}
                </div>
                
            </div>

        </div>
    </div>    
</div>    


tab2.html
<!--/ Content -->
<div class="container-fluid" id="mainContent">
    <div class="row">
        <div class="col-lg-7 col-md-7">
            <h2>Business Summary</h2>
            <div class="col-lg-3 col-md-3 col-sm-12 col1">
                <div class="col-lg-12 col-md-12 col-sm-4 col-xs-12 num">
                  Tomorrow is: {{ textOutput('tomorrow')}}
                </div>
                
            </div>

        </div>
    </div>    
</div>          

The app then shows only the divs with the text "Today is:" and "Tomorrow is:" but the values of output$today and output$tomorrow don't render:

If I change UI to only include tab 1:

shinyUI(
  navbarPage(
    'Project', 
    header = HTML('<meta charset="utf-8">
                   <meta http-equiv="X-UA-Compatible" content="IE=edge">
                   <meta name="viewport" content="width=device-width, initial-scale=1">'
    ),
    theme = 'css/style.css',
    tabPanel('Summary',
             htmlTemplate("tab1.html")
    )#,
    # tabPanel('Tab2',
    #          htmlTemplate("tab2.html")
    # )
    # 
    
  )
)

then it works as expected.

Joe Cheng

unread,
Mar 28, 2017, 4:48:25 PM3/28/17
to David Croushore, Shiny - Web Framework for R
If you browse to the app from a web browser, do you see any errors in your browser's JavaScript console?

--
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/46ddd5a3-b089-479f-8b74-118098a31844%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Croushore

unread,
Mar 28, 2017, 4:57:12 PM3/28/17
to Shiny - Web Framework for R, david.c...@gmail.com
Ahh... looks like it doesn't like me trying to reference the same output from both templates in the full app.

So if there is something I want to render on multiple tabs (in this case, everything on the summary tab shows up elsewhere), do I just need to do something like this? Or is there a better way to recycle the object?
output$metric<- renderText({blah})
output$metric_summary
<-renderText({same blah})


Bárbara Borges

unread,
Mar 28, 2017, 8:30:56 PM3/28/17
to Shiny - Web Framework for R, david.c...@gmail.com
You can do that, but what I'd recommend is using modules (https://shiny.rstudio.com/articles/modules.html) so that you get namespacing for free
Message has been deleted
Message has been deleted

Nacho Castejón

unread,
May 5, 2017, 7:26:27 AM5/5/17
to Shiny - Web Framework for R
Hi all,
just in case anyone else ends up in this thread the way I did: I had a similar problem, where only the tab set initially as active was updating, and I solved it by including the htmlTemplate element in a fluidPage container. 

Regards,
Reply all
Reply to author
Forward
0 new messages