conditionalPanel() not working in shiny and showing output which should be hidden.

I tried every way possible on the internet but it does not work.

Please note - i have modified the code and there might be a bracket extra but my server shows no error except that the conditional statement shows even before i click on 'X'

**server.R**
fluidPage(
  navbarPage("hi" ),
  tabsetPanel(
    tabPanel("Submit job",
             hr(),
             fluidRow(
               column(5,
                      wellPanel(
              
                        textInput("text", "1.  Enter name", "title"),
                        verbatimTextOutput("value"),
                        
                        awesomeCheckboxGroup("methods", label = ("methods available"),
                                             choices = list("one"='X', "two"='Q'),
                                             selected = "X", inline = FALSE, status = "primary"),
                  
                      # if methods = X then execute below.
                       conditionalPanel(condition="input.methods == 'X'",
                                         wellPanel(
                                           radioButtons(inputId = "matrix",
                                                        label = "matrix multiply",
                                                        choices = c("one", "two"),
                                                        selected = "one",
                                                        inline = T)
                                         ))
)
)))
)

You have programatically set input$methods to X at the point you define it?

Hi. Nope. I am just saving an input into methods for one option and calling it X. Isn’t that right?

There are choices that you set by your list, but you went further and dictated a select(ion)

Hi Could you please explain more with a code snippet?

Change to

selected = "Q",

Hi. I tried that still it doesn’t work.

It doesnt work ?

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  awesomeCheckboxGroup("methods",
    label = ("methods available"),
    choices = list("one" = "X", "two" = "Q"),
    selected = "Q", inline = FALSE, status = "primary"
  ),

  # if methods = X then execute below.
  conditionalPanel(
    condition = "input.methods == 'X'",
    wellPanel(
      radioButtons(
        inputId = "matrix",
        label = "matrix multiply",
        choices = c("one", "two"),
        selected = "one",
        inline = T
      )
    )
  )
)

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

shinyApp(ui, server)

It still does not work. is it because i am using
fluidpage, navbarpage, tabsetpanel, tabpanel, fluidrow () in that order!

kindly suggest?

I cant see what youve been typing..., but what I shared does work.

thats my whole ui.R file. Kindly look at it and tell me whats off here? :frowning_face:

# ui.R
fluidPage(
  
  ###### use a gradient in background
  setBackgroundColor(
    color = c("#D2691E", "#F7FBFF"),
    gradient = "linear",
    direction = "bottom"
  ),
  

navbarPage("methods of interest", theme = shinytheme("yeti") ),
  tabsetPanel(
    tabPanel("Submit job",
             hr(),
             fluidRow(
               column(5,
                      wellPanel(
                        textInput("text", "1.  Enter experiment name", "title"),
                        verbatimTextOutput("value"),
                        
                        awesomeCheckboxGroup("methods",
                                             label = ("methods available"),
                                             choices = list("one" = "X", "two" = "Q"),
                                             selected = "Q", inline = FALSE, status = "primary"
                        ),
                        
                        conditionalPanel(
                          condition = "input.methods == 'X'",
                          wellPanel(
                            radioButtons(
                              inputId = "matrix",
                              label = "matrix multiply",
                              choices = c("one", "two"),
                              selected = "one",
                              inline = T
                            )
                          )
                        ),
                        
                        fileInput("file", "3a.  Enter custom file", accept = c(".csv", ".txt")),
                        h5("OR"),
                        
                        
                        
                        hr(),
                        fluidRow(column(3, verbatimTextOutput("value"))),
                        
                        
                        actionButton("goButton", "Submit!")
                        
                      ),
                      
               )
               
             )
    ),
    
    navbarMenu("Tables & Plots",
               tabPanel("1"),
               tabPanel("2")
               ) ))

you have apparently broken your UI by placing verbatimTextOutput("value") twice, as all ui items should have unique id's. reusing an id is hard to debug, and has unpredictable effects, always watch out for it !

1 Like

Thank you! works now!

I ran into another issue now- conditionalPanel() not working with || as it does not show the radio buttons when i choose both methods.
Hi, the conditional panel for example (ui.R):

awesomeCheckboxGroup("method", label = (" Methods class 1 available"), choices = list("one" = "M", "two" = "S"), selected = "M", inline = FALSE, status = "primary" ),
         # if method = M or S then execute below.
        conditionalPanel(
           condition = "(input.method == 'M' || input.method == 'S')",
           wellPanel(
             prettyRadioButtons(inputId = "data", "Choose our data",
                                c("data1"="dat1", "data2"="dat2"), status = "primary"),
           )
         )

Now the issue is that this does not show the radio buttons when I choose both methods"one" and "two". Kindly help me.

My javascript knowledge is much less than my r.
But I can tell you why it's not working.
When you select both, then input method is neither m nor s but a composite of m and s. So perhaps you can test for absence of a string or value in javascript and negate that

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.