2017-03-17 145 views
1

我想创建一个闪亮的应用程序,使用tabsetPanel,但是当我创建选项卡,在应用中的内容不再填充窗口的整个空间和叶上白色的大缺口不填充整个页面正确和低于输出。以下是它发生的一个非常基本的例子。没有选项卡,该应用程序完美地作为一个流动页面工作,但对于我正在做的工作,我需要将其分解为选项卡。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,但它要么使情况变得更糟通过将对象移动到错误的地方或者什么都没有发生。这是发生在我身上吗?有没有人有任何想法是什么原因可以做到这一点,如果是的话,它是如何解决的?

+0

如果要调整标签集面板的宽度和高度,这篇文章可能会有所帮助:https://stackoverflow.com/questions/19096439/shiny-how-to-adjust-the-width-of-the -tabsetpanel –

回答

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左右。没有它,一切都很好。

+0

完美,谢谢!没有意识到这是我出错的地方。 – MLMM