Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)
like image 515
Kevin Ho Avatar asked Jun 26 '26 15:06

Kevin Ho


1 Answers

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"
like image 80
Stéphane Laurent Avatar answered Jun 29 '26 05:06

Stéphane Laurent



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!