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

I create two graphs.

Right now they are displayed 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 I can show these graphs one below the other on the same panel, and not two different panels, as of now. Thanks to the people for their help.

+4
source share
1 answer

You can wrap them in fluidRowor just list them inside the sametabPanel

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 fluidRowprovides easy control over individual plot attributes, such as width,

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

Source: https://habr.com/ru/post/1612166/


All Articles