如何确定反应性地显示哪个图

How to determine which plot is shown reactively

这里有两个我想在APP中展示的情节。在 ui.r 中,我有一个输入(绘图类型)和一个输出(绘图)。

绘图类型输入:

sidebarPanel(
             checkboxGroupInput("vo", 
                                label = "Visualization Object", 
                                choices = list("Polar Distance of VAR from nadir" = 1, 
                                               "Real Value of VAR" = 2 
                                ),
                                selected = c(1,2)
             )
           )

和绘图输出:

fluidRow(
           column(6,
                  plotOutput(outputId="polar", width = "600px", height = "600px")
           ),
           column(6,
                  plotOutput(outputId="paral", width = "600px", height = "600px")
           )
         )

在server.r中,我用这个:

if(1%in%vo){
  output$polar <- renderPlot({
    # input$reset

    ap(whole_p[[ts$counter]])
  })}
  if(2%in%vo){
  output$paral <- renderPlot({
    # input$reset

    av(whole_v[[ts$counter2]])
  })}

那么我如何更改服务器代码以使其工作:当我 select Polar Distance of VAR from nadir 时,ui 中仅显示情节 output$polar,当 select Real Value of VAR 时,ui 中仅显示情节 output$paral。谢谢。

这是一个基于conditionalPanel

的有效解决方案
library(shiny)

ui <- shinyUI(fluidPage(

   titlePanel("Old Faithful Geyser Data"),

   sidebarLayout(
      sidebarPanel(
        checkboxGroupInput("vo", 
                           label = "Visualization Object", 
                           choices = list("Polar Distance of VAR from nadir" = 1, 
                                          "Real Value of VAR" = 2 
                           ),
                           selected = c(1,2)
        )
      ),

      mainPanel(
        conditionalPanel(condition = "input.vo.indexOf('1') >= 0", plotOutput(outputId="polar", width = "600px", height = "600px")),
        conditionalPanel(condition = "input.vo.indexOf('2') >= 0", plotOutput(outputId="paral", width = "600px", height = "600px"))
      )
   )
))

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

    output$polar <- renderPlot({
      plot(mtcars$mpg, mtcars$cyl)
    })
    output$paral <- renderPlot({
      plot(mtcars$disp, mtcars$hp)
    })
})

shinyApp(ui = ui, server = server)