Kevin Ho
Kevin Ho

Reputation: 107

conditionalPanel conditioned on multiple selectInput

I want to set a condition on the conditionalPanel such that as long as selectInput contains 1, the conditionalPanel will show.

I am not familiar with JavaScript, can someone help?

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)

Upvotes: 3

Views: 121

Answers (2)

St&#233;phane Laurent
St&#233;phane Laurent

Reputation: 84599

Given a JavaScript array arr, the index of element x in arr is given by arr.indexOf(x). If x does not belong to arr, then arr.indexOf(x) returns -1.
So the condition you're looking for is

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

Upvotes: 3

Subhasish1315
Subhasish1315

Reputation: 978

if I am understanding Correctly your issue is --you want to print "Success" till '1' is selected... If this is you issue you can try this below..

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)

Please let me know if this works...

Upvotes: 0

Related Questions