我正在尝试tabsetPanel
在mainPanel
Shiny 应用程序中包含多个。当我启动应用程序时,它没有显示任何内容,就好像应用程序试图找出 UI 元素而根本没有进入服务器元素。
有谁知道为什么会这样?
下面是一个基于 RStudio 中 Shiny 应用程序模板的最小示例。
用户界面
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")))
)
)
))
服务器
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')
})
})
你的输出必须是独一无二的,你不能有多个"distPlot"
,改为这样的:
data <- reactive({
# 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')
})
output$distPlot1 <- renderPlot({
data()
})
output$distPlot2 <- renderPlot({
data()
})
然后在你的 ui
plotOutput("distPlot1")
plotOutput("distPlot2")
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句