我正在尝试使用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 :(得分: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
。没有它,一切看起来都很好。