All in one!

We have created 5 simple apps. It is time to put it all together. We will do the following:

  • Use the navbarPage() to create a top level navigation bar.

  • Create three separate tabs in the navigation bar.

  • Create subtabs in these tabs.

  • Distribute the apps we created in these tabs.

  • Choose a theme from shinythemes package.

  • Add a logo.

Navigation bar with 3 tabs

Subtabs

In fact, we can put a tabsetPanel() inside the tabPanel() so that we have another level of tabs under each tab.

navbarPage("App Title",
  tabPanel("tab1",
           tabsetPanel(
             tabPanel("Subtab1",
                      #put whatever you like in this subtab
                      ),
            tabPanel("Subtab2",
                     #put whatever you like in this subtab
                    )
           )),
  tabPanel("tab2",
           #put whatever you like in this tab
           )
)

Distribute the apps in different tabs!

  navbarPage("App Title",
             tabPanel("tab1",
                      #put fifth app tab1 here
                      ),
             tabPanel("tab2",
                      mainPanel(tabsetPanel(
                        tabPanel("Subtab1",
                                 #put first app here
                        ),
                        tabPanel("Subtab2",
                                 #put fifth app tab2 here
                        )
                      ))),
             tabPanel("tab3",
                      mainPanel(tabsetPanel(
                        tabPanel("Subtab1",
                                 #put second app here
                        ),
                        tabPanel("Subtab2",
                                 #put third app here
                        ),
                        tabPanel("Subtab3",
                                 #put fourth app here
                                 )
                      )))
  )

Add a theme

We can also add a theme very easily using shinythemes package. Here, I picked the ‘cerulean’ theme.

#load library
library(shinythemes)

ui <- fluidPage(theme = shinytheme("cerulean"),
                #the rest of your code
                )

Add a logo

A few things to watch out for

In the first four of our apps, we had the titlePanel() . Remove those and put those titles as titles for the tab or subtab.

There are a lot of parentheses and curly brackets in the code. Make sure those are all accounted for. Otherwise you will get an error!

Lastly, make sure you import all the necessary libraries and datasets at the beginning of the app.

Final app done!

You can download the code final.R and make sure it is in the same directory as the folder dataforshiny.