【问题标题】:TabsetPanel not filling whole page in ShinyTabsetPanel 没有在 Shiny 中填满整个页面
【发布时间】:2017-03-18 00:05:17
【问题描述】:

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

一个简单的例子:

`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,但要么将对象移动到错误的位置而使情况变得更糟,要么根本没有任何反应。难道只有我会发生这种情况吗?有谁知道它这样做的原因是什么,如果是这样,如何解决?

【问题讨论】:

标签: r tabs shiny


【解决方案1】:

这是一个横跨整个宽度的:

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 周围。没有它一切看起来都很好。

【讨论】:

  • 完美,谢谢!没有意识到这是我出错的地方。
猜你喜欢
  • 1970-01-01
  • 2019-09-22
  • 1970-01-01
  • 2021-09-12
  • 1970-01-01
  • 2011-04-12
  • 1970-01-01
  • 2011-08-30
  • 1970-01-01
相关资源
最近更新 更多