Luigi
Luigi

Reputation: 21

javascript condition contains for conditionalpanel in shiny

I'm working on a Shiny app and want to add a tabpanel if a condition is TRUE. I'm using conditionalpanel function and the condition to be tested is whether or not "products" from ui input contains "C".

From the first tab, if C is clicked the "second tab" is not shown.

I think the issue is the JS condition inside the conditionalpanel.

If you have any working solution (not necessarily based on conditionalpanel) I'll appreciate your help and support. Luigi

Here below my reprex

library(shiny)
library(shinydashboard)
library(shinyWidgets)
library(reprex)

tab_input <- dashboardPage(
  dashboardHeader(title = "Value boxes", disable = TRUE),
  dashboardSidebar(disable = TRUE),
  dashboardBody(
    fluidRow(
      box(
        checkboxGroupButtons(
          inputId = "products", label = tags$h1("Select products"), 
          choices = c("A", "B", "C"),
          checkIcon = list(yes = icon("ok", lib = "glyphicon"), no = icon("remove", lib = "glyphicon"))
        )
      )
    )
  )
)


ui <- navbarPage("my APP", 
                 tabPanel("first tab",
                          tab_input),
                 
                          conditionalPanel(
                            condition = "input.products.contains('C')",
                            tabPanel("second_tab",
                            dashboardPage(
                              dashboardHeader(title = "Value boxes", disable = TRUE),
                              dashboardSidebar(disable = TRUE),
                              dashboardBody(
                                
                              )
                              )
                            )
                          )
                 )

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

}

shinyApp(ui, server)

Upvotes: 1

Views: 750

Answers (1)

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

Reputation: 84659

Try

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

Upvotes: 1

Related Questions