Center MainPanel in R Shiny

I am having trouble aligning the mainPanel in the UI of my ShinyApp to 'center'. I know that the widths of the mainPanel & sidebarPanel should add up to 12, but how would I change the width of the mainPanel to be something less (for example, 8) and then center the mainPanel on the page (so with 2 widths' worth of space on each side of the mainPanel display)?

Any help would be greatly appreciated!

Here is a very rough example. The widths need not add to 12. Any unused width will just be blank.


ui <- fluidPage(
  titlePanel("Mock App"),
    sidebarPanel(  width = 2, 
                   fluidRow(  h1("Sidebar Title"),
                              actionButton("Bttn1", "Press Me")),
                   fluidRow(  actionButton("Bttn2", "Press Me")),
                   fluidRow(  actionButton("Bttn3", "Press Me")), 
                   fluidRow(  actionButton("Bttn4", "Press Me"))
    mainPanel(width = 8, style = "border-style: solid; border-color: black",
              h1("Main Panel Header"),
              plotOutput("Plot1", height = "350px", width = "100%")
) #Close FluidPage

server <- function(input, output) {
   output$Plot1 <- renderPlot({
      plot(seq(0,10), seq(100, 110), col = "red")

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

Also, you need not use the sidebarLayout if it does not fit your needs. You can use fluidRow() and divide that into horizontal pieces with column()

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.