闪亮的对多个 tabsetpanels 没有响应

莫霍武

我正在尝试tabsetPanelmainPanelShiny 应用程序中包含多个当我启动应用程序时,它没有显示任何内容,就好像应用程序试图找出 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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章