如何确定哪个地块被反应显示

时间:2016-05-11 20:38:44

标签: shiny-server shiny

以下是我想在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]])
  })}

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

1 个答案:

答案 0 :(得分:1)

以下是基于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)