闪亮不响应多个tabsetpanels

我试图在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')

})

})

回答:

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

以上是 闪亮不响应多个tabsetpanels 的全部内容, 来源链接: utcz.com/qa/265771.html

回到顶部