TabsetPanel not filling whole page in Shiny

我们两清 提交于 2020-05-16 03:26:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/42861026/tabsetpanel-not-filling-whole-page-in-shiny

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!