3

I have two shiny apps with ui and server compoents. I need to create one app and be able to open the each application with tabs. Clicking on one tab will bring the app.

first app is like this:

ui <- pageWithSidebar(....)
server <- function(input, output,session) {....}

second app is something like this:

 shinyUI(....)
server <- function(input, output, session) {.....}

How could I create one app and refer to these apps from tabs within one app?

user1471980
  • 10,127
  • 48
  • 136
  • 235

1 Answers1

1

As far as I know, this could be achieved in two ways.

  1. Simple shiny app:

You can create tabs using tabPanel(title, ...) function and then wrapping all the tabPanel()s inside a tabsetPanel() function.

So, in your case you can put all the UI elements of your first app inside the first tabPanel('unique_title') and so on.

This will help you create multiple independently viewable sections.

You can refer these two links to know more http://shiny.rstudio.com/reference/shiny/latest/tabPanel.html

  1. As @Michal suggested, using shinydashboard:

shinydashnoard is another package that you will have to install in order to use this feature of shiny. It basically has a predefined structure with a header, a sidebar and a body.

The basic structure is shown below:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashbaordSidebar(),
  dashboardBody()
)

server <- function(input,output,server){...}

Normally, dashboardSidebar() is used for navigation. However, it can contain menuItem() that behave like tabs in a tabPanel().

For your case, you can add multiple menuItem()s inside sidebarMenu() as shown below

Updated Code

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(
      menuItem("first_app", tabName = "first_app"),
      menuItem("second_app", tabName = "second_app")
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName = "first_app",
              h2("First App Content")
      ),
      tabItem(tabName = "second_app",
              h2("Second App Content"))
    )
  )
)

server <- function(input,output,server){}

shinyApp(ui,server)

This will create a basic dashboard page with 2 menu items.

You can also refer to link below to know more about the shinydashboard structure https://rstudio.github.io/shinydashboard/structure.html

I hope this helps :)

Niket
  • 146
  • 9