rshiny

How do I reduce the width of the sidebar panel in an R Shiny web app?


library(shiny)

ui <- fluidPage(

    titlePanel("Hello"),
    sidebarLayout(
        sidebarPanel("Hello SideBar"),
        mainPanel("Hello MainPanel")
    )
)

server <- function(input, output) {

    
}

shinyApp(ui = ui, server = server)

Just by eyeballing I can tell right now my sidebar panel takes up about 33% of the width of the screen. Any idea how I can reduce the width of the sidebar so that the main Panel is larger?


Solution

  • sidebarPanel has a width argument

    width: The width of the sidebar. For fluid layouts this is out of 12 total units; for fixed layouts it is out of whatever the width of the sidebar's parent column is.

    The default width is 4, which confirms your eyeballing estimate that 4/12 is one third. So to make it e.g 1/2 the current width you would do:

    ui <- fluidPage(
    
        titlePanel("Hello"),
        sidebarLayout(
            sidebarPanel("Hello SideBar", width=2),
            mainPanel("Hello MainPanel")
        )
    )