0
我試圖在Shiny應用程序的mainPanel
中包含多個tabsetPanel
。當我啓動應用程序時,它沒有顯示任何東西,就好像應用程序試圖找出UI元素而根本沒有進入服務器元素。閃亮不響應多個tabsetpanels
任何人都知道爲什麼會出現這種情況?
以下是基於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')
})
})