闪亮的渲染仪表板主体

问题描述 投票:2回答:1

我要在所选选项上重新显示仪表板主体。但是在当前情况下,即使选择其他选项,仍会首先渲染主体。

它甚至在顶部显示错误消息错误:“关闭”类型的对象不可子集化]

enter image description here

当我选择选项B时,我得到的是它,它不应显示A,而当我再次选择选项A时,B仍然出现

enter image description here

ui <- dashboardPage(
  dashboardHeader(title = "Title",titleWidth = 200),
  dashboardSidebar(
    selectInput("info", "Please choose:", 
                c("A"= "A",
                  "B"= "B"))),
  dashboardBody(
    uiOutput("main"),
    fluidRow(
      box(
        valueBoxOutput("A",width = 12))
    ),
    fluidRow(
      box(
        valueBoxOutput("B",width = 12))
    )
  ) 
)

server <- function(input, output, session) {

  output$main <- renderUI({
    if (input$info == 'A') {
      AFun()
    } else{
      BFun()
    }
  })

    AFun <- reactive({
      output$A <- renderValueBox({
        valueBox("A","A", color = "blue")
      })      
    })

    BFun <- reactive({
      output$B <- renderValueBox({
        valueBox("B","B", color = "green")
      })  
    })
}
shinyApp(ui = ui, server = server)

我该如何实现?

是否有一种方法可以在选择时重新显示仪表板主体?

r shiny shinydashboard shiny-reactivity
1个回答
0
投票

有几种方法可以做您想要的事情。 conditionalPanel是一种方式,uiOutput / renderUI是另一种方式。一个简单的Google搜索就会给您this

© www.soinside.com 2019 - 2024. All rights reserved.