TabsetPanel 没有在 Shiny 中填充整个页面 [英] TabsetPanel not filling whole page in Shiny

查看:23
本文介绍了TabsetPanel 没有在 Shiny 中填充整个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个使用 tabsetPanel 的闪亮应用程序,但是当我创建选项卡时,应用程序中的内容不再填满窗口的整个空间,并在输出的右侧和下方留下大的白色间隙.下面是它发生的一个非常基本的例子.如果没有标签,该应用程序可以完美地作为一个流畅的页面,但对于我正在做的工作,我需要将其拆分为标签.

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.

一个简单的例子:

`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) ` 

我试图摆弄fillPage和fluidPage,但要么通过将对象移动到错误的位置使情况变得更糟,要么什么也没有发生.只有我有这种情况吗?有谁知道它这样做的原因是什么,如果是这样,如何解决?

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?

推荐答案

这是一个跨越整个宽度的方案:

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) 

基本上你有一个 mainPanel 包裹在 tabsetPanel 周围.没有它,一切看起来都很好.

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

这篇关于TabsetPanel 没有在 Shiny 中填充整个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆