MLMM
MLMM

Reputation: 95

TabsetPanel not filling whole page in Shiny

I am trying to create a shiny app that uses tabsetPanel, however when I create the tab, the content in the app no longer fills the whole space of the window and leaves large white gaps on the right and below the output. Below is a very basic example that it happens to. Without tabs the app works perfectly as a fluid page but for the work I'm doing I need it split up into tabs.

A simple example:

`library(shiny)

# Define UI for application that draws a histogram
ui <- fluidPage(

# Application title
titlePanel("Old Faithful Geyser Data"),


mainPanel(
 tabsetPanel(
   tabPanel("Test",
# Sidebar with a slider input for number of bins 
sidebarLayout(
  sidebarPanel(
     sliderInput("bins",
                 "Number of bins:",
                 min = 1,
                 max = 50,
                 value = 30)
  ),

  # Show a plot of the generated distribution
  mainPanel(
     plotOutput("distPlot")
  )
 )),
 #Create second tab just for demonstration
 tabPanel("Second Test", h3("Test")
        ))))


# Define server logic required to draw a histogram
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')
 })

 { "example second tab" }
}

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

I have tried to fiddle around with fillPage and fluidPage but either it makes it worse by moving the objects into the wrong places or nothing at all happens. Is it just me this is happening to? Does anyone have any idea what could be the reason it does this and if so how it can be solved?

Upvotes: 4

Views: 4993

Answers (1)

mRcSchwering
mRcSchwering

Reputation: 894

Here is one that spans over the whole width:

library(shiny)

ui <- fluidPage(
    titlePanel("Title"),
    tabsetPanel(
      tabPanel(
        "Test",
           sidebarLayout(
             sidebarPanel(
               sliderInput("bins", "Number of bins:", min = 1, max = 50, value = 30)
             ),
             mainPanel(
               plotOutput("distPlot")
             )
           )
      ),
      tabPanel("Second Test", h3("Test"))
    )
)

server <- function(input, output) {
  output$distPlot <- renderPlot({
    x    <- faithful[, 2] 
    bins <- seq(min(x), max(x), length.out = input$bins + 1)
    hist(x, breaks = bins, col = 'darkgray', border = 'white')
  })
  { "example second tab" }
}

shinyApp(ui = ui, server = server) 

Basically you had a mainPanel wrapped around the tabsetPanel. Without it everything looks fine.

Upvotes: 5

Related Questions