【发布时间】:2017-12-27 14:39:43
【问题描述】:
我正在尝试在 Shiny 应用的 mainPanel 中包含多个 tabsetPanel。当我启动应用程序时,它没有显示任何内容,就好像应用程序试图找出 UI 元素而不进入服务器元素一样。
有人知道为什么会这样吗?
以下是基于 RStudio 中 Shiny 应用模板的最小示例。
ui.R
library(shiny)
# Define UI for application that draws a histogram
shinyUI(fluidPage(
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
sliderInput("bins",
"Number of bins:",
min = 1,
max = 50,
value = 30)
),
# Multiple tabset panels
mainPanel(
h2("tabsetpanel1"),
tabsetPanel(id = "pan1",
type = "tabs",
tabPanel("tab1", plotOutput("distPlot"))),
h2("tabsetpanel2"),
tabsetPanel(id = "pan2",
type = "tabs",
tabPanel("tab2", plotOutput("distPlot")))
)
)
))
server.R
library(shiny)
# Define server logic required to draw a histogram
shinyServer(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')
})
})
【问题讨论】: