【问题标题】:conditionalPanel does not work条件面板不起作用
【发布时间】:2015-11-23 07:21:06
【问题描述】:

我有一个要在闪亮应用中显示的数据框。我使用一些selectInput 函数来对我的数据进行子集化。我还想使用函数conditionalPanel 仅显示部分数据。取决于所选的渠道。不幸的是,我使用的方法没有显示任何表格。有人有什么建议吗?

希望所有括号都在正确的位置,因为我为公众更改了一些代码。

数据:

  data_test = data.frame(ID = c ("1","2","3","4","5"),
                  product = c("A","B","C","A","C"),
                  milieu = c("good","medium","bad","medium","bad"),
                  online = c(1,0,1,1,0),
                  ooh = c(0,1,0,1,1),
                  event = c(1,1,0,0,0))

用户界面:

shinyUI(fluidPage(
  titlePanel("product milieu"),

  sidebarLayout(
    sidebarPanel("select",
                 selectInput("select_milieu",
                             label = "Milieu",
                 choices = list("good",
                                "medium",
                                "bad")
                 ),
                 selectInput("select_product", 
                             label = "Product",
                             choices = list("A", 
                                            "B", 
                                            "C")
                 ),
                 selectInput("select_channel", 
                             label = "channel",
                             choices = c("online",
                                         "ooh",
                                         "event"))),
    mainPanel("My table",
              textOutput("output_milieu"),
              textOutput("output_product"),
              conditionalPanel(condition = "select_cannel == 'online'",
                               tableOutput("gapminder_table_online")),
              conditionalPanel(condition = "select_cannel == 'ooh'",
                               tableOutput("gapminder_table_ooh")),
              conditionalPanel(condition = "select_cannel == 'event'",
                               tableOutput("gapminder_table_event"))
              )
  )
))

服务器:

shinyServer(function(input, output) {

  output$gapminder_table_online <- renderTable({ 
    subset(data_test[,2:4],
           milieu == input$select_milieu & product == input$select_product)

  })

  output$gapminder_table_event <- renderTable({ 
    subset(data_test[,c(2,3,5)],
           milieu == input$select_milieu & product == input$select_product)

  })

  output$gapminder_table_ooh <- renderTable({ 
    subset(data_test[,c(2,3,6)],
           milieu == input$select_milieu & product == input$select_product)

  })

  output$output_milieu <- renderText({
    paste("milieu", input$select_milieu)
  })
  output$output_product <- renderText({
    paste("product", input$select_product)
  })
  output$output_cannel <- renderText({
    paste("cannel", input$select_cannel)
  })
})

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    您的条件有错字(“select_channel”中缺少“h”),并且也没有完整指定输入变量。如下所示更新它们,然后它应该可以按需要工作:

    ...
    conditionalPanel(condition = "input.select_channel == 'online'",
                               tableOutput("gapminder_table_online")),
    conditionalPanel(condition = "input.select_channel == 'ooh'",
                               tableOutput("gapminder_table_ooh")),
    conditionalPanel(condition = "input.select_channel == 'event'",
                               tableOutput("gapminder_table_event"))
    ...
    

    不过,我觉得我应该注意,您的代码似乎肯定还有其他问题。

    【讨论】:

      猜你喜欢
      • 2016-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多