Search code examples
rshinypanel

Panel aligned in shiny


Guys I took the executable code that shiny provides and added another panel. How do I leave the second panel under the first? Is it possible ??? Thank you very much!

library(shiny)

ui <- fluidPage(


    titlePanel("Old Faithful Geyser Data"),

    sidebarLayout(
        sidebarPanel(
            sliderInput("bins",
                        "Number of bins:",
                        min = 1,
                        max = 50,
                        value = 30)
        ),

        sidebarLayout(
            sidebarPanel(
                sliderInput("bins",
                            "Number of bins:",
                            min = 1,
                            max = 20,
                            value = 30),
            ),
        mainPanel(
           plotOutput("distPlot")
        )
    )
))

server <- function(input, output) {

    output$distPlot <- renderPlot({
        # generate bins based on input$bins from ui.R
        x    <- faithful[, 2]
        bins <- seq(min(x), max(x), length.out = input$bins + 1)

        # draw the histogram with the specified number of bins
        hist(x, breaks = bins, col = 'darkgray', border = 'white')
    })
}

# Run the application 
shinyApp(ui = ui, server = server)

Thank you very much friends!


Solution

  • You don't need an additional sidebarLayout and sidebarPanel. You can just put the second slider below the first. tags$hr() here is to visually separate them if you need to.

      sidebarLayout(
        sidebarPanel(
          sliderInput("bins",
                      "Number of bins:",
                      min = 1,
                      max = 50,
                      value = 30),
          tags$hr(),
          sliderInput("bins",
                      "Number of bins:",
                      min = 1,
                      max = 20,
                      value = 30)
        )