【问题标题】:conditionalPanel conditioned on multiple selectInputconditionalPanel 以多个 selectInput 为条件
【发布时间】:2020-01-19 07:24:41
【问题描述】:

我想在 conditionalPanel 上设置一个条件,只要 selectInput 包含 1,就会显示 conditionalPanel。

我不熟悉 JavaScript,有人可以帮忙吗?

library(shiny)
library(shinydashboard)

ui <- function() {
  dashboardPage(dashboardHeader(),
                dashboardSidebar(
                  selectInput(inputId = "month", label = "Month", choices = 1:12, multiple = TRUE)
                ),
                dashboardBody(
                  conditionalPanel(condition = "input.month == '1'", h1("success"))
                ),
                skin = "blue")
}

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

}

shinyApp(ui, server)

【问题讨论】:

    标签: javascript r shiny shinydashboard


    【解决方案1】:

    给定一个 JavaScript 数组 arrarr 中元素 x 的索引由 arr.indexOf(x) 给出。如果x不属于arr,则arr.indexOf(x)返回-1
    所以你要找的条件是

    condition = "input.month.indexOf('1') > -1"
    

    【讨论】:

      【解决方案2】:

      如果我理解正确,您的问题是——您想打印“成功”,直到选择“1”...如果这是您的问题,您可以在下面尝试这个..

      library(shiny)
      library(stringr)
      library(shinydashboard)
      
      ui <- function() {
        dashboardPage(dashboardHeader(),
                      dashboardSidebar(
                        selectInput(inputId = "month", label = "Month", choices = 1:12, multiple = TRUE)
                      ),
                      dashboardBody(
                        #conditionalPanel(condition = "input.month == '1'", h1("success"))
                        uiOutput("output")
                      ),
                      skin = "blue")
      }
      
      server <- function(input, output, session) {
      
        output$output<-renderUI({
          if("TRUE" %in% str_detect(input$month,'1')==TRUE)
          {
            h1("Success")
          }
          else
          {
            returnValue()
          }
        })
      }
      
      shinyApp(ui, server)
      

      如果可行,请告诉我...

      【讨论】:

        猜你喜欢
        • 2018-09-21
        • 2017-07-05
        • 2016-02-03
        • 1970-01-01
        • 2019-10-23
        • 2015-10-28
        • 1970-01-01
        • 2019-09-20
        • 2019-08-24
        相关资源
        最近更新 更多