我正在尝试创建一个使用 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) `
Run Code Online (Sandbox Code Playgroud)
我试图摆弄fillPage和fluidPage,但要么通过将对象移动到错误的位置而使情况变得更糟,要么什么也没有发生。只有我有这种情况吗?有谁知道它这样做的原因是什么,如果是这样,如何解决?
这是一个跨越整个宽度的:
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)
Run Code Online (Sandbox Code Playgroud)
基本上你有一个mainPanel包裹在tabsetPanel. 没有它,一切看起来都很好。