Plotting two graphs, one below the other, in shiny panel

Bridgeport Byron Tucker picture Bridgeport Byron Tucker · Oct 19, 2015 · Viewed 21.4k times · Source

I am producing two graphs.

Right now they are showing up in two different panels (tabs)

ui.r
mainPanel(
      tabsetPanel(
        tabPanel("Summary", dataTableOutput("dis")),
        tabPanel("Plot", plotOutput("plot1")),
        tabPanel("Plot", plotOutput("plot2"))
      )
    )

server.r

output$plot1 <- renderPlot({
    Plot1
  })


output$plot2 <- renderPlot({
    Plot1
 })

I am wondering how can i show these graphs one below the other in the same panel, and not two different panels like how it is now. Thanks folks for helping.

Answer

Rorschach picture Rorschach · Oct 19, 2015

You can wrap them in a fluidRow or just list them inside the same tabPanel

shinyApp(
    shinyUI(
        fluidPage(
            mainPanel(
                tabsetPanel(
                    tabPanel("Summary", dataTableOutput("dis")),
                    tabPanel("Plot",
                             # fluidRow(...)
                                 plotOutput("plot1"),
                                 plotOutput("plot2")
                             )
                )
            )
        )
    ),
    shinyServer(function(input, output) {
        output$plot1 <- renderPlot({
            plot(1:10, 1:10)
        })

        output$plot2 <- renderPlot({
            plot(1:10 ,10:1)
        })

        output$dis <- renderDataTable({})
    })
)

Wrapping them in a fluidRow provides easy control over individual plot attributes like widths for example,

tabPanel("Plot",
         fluidRow(
             column(8, plotOutput("plot1")),
             column(12, plotOutput("plot2"))
         ))