9

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.

Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
  • 3
    for ggplot2 plots you can do `grid.arrange(gplot, gplot, ncol=1)`. for base plots you can do `par(mfrow=c(2,1)) ; plot(…) ; plot(…); par(mfrow=c(1,1))` – hrbrmstr Oct 18 '15 at 23:17

2 Answers2

19

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"))
         ))
Rorschach
  • 31,301
  • 5
  • 78
  • 129
0

If we do it like this:

tabPanel("Plot",
    plotOutput("plot1"),
    plotOutput("plot2")
    )

plot1 will show on the top and plot2 will show on the bottom. But if we do it using fluidRow:

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

Then we can show the two plots side by side.