【问题标题】:Shiny not responsive to multiple tabsetpanelsShiny 对多个 tabsetpanels 没有响应
【发布时间】: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')

  })

})

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    你的输出必须是唯一的,你不能有多个"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")
    

    【讨论】:

      猜你喜欢
      • 2020-08-15
      • 2017-11-21
      • 1970-01-01
      • 1970-01-01
      • 2021-12-18
      • 2019-02-21
      • 1970-01-01
      • 2021-12-13
      • 1970-01-01
      相关资源
      最近更新 更多