0

I have a checkboxGroupInput that should only be shown if a specific radioButton "continent" is selected. I tried to use conditionalPanel, but it doesn't work, it never shows the checkboxes , whichever radio button you choose.

This is my code, I don't understand what the problem could be ...

app.r

tabItem( tabName = "3dGlobe",
               fluidRow(
                 column( width = 4,
                   box(
                     radioButtons("filters", "Filters" , choiceNames = list("All","Some continents") , choiceValues = list("all","continent")),
                     conditionalPanel(
                       condition = "input.filters == 'continent'",
                       uiOutput("continentCheckbox")
                    )
                   )
                  ),
                 column( width = 1,
                  globeOutput("globe", width = "500px" , height = "500px")
                 )
                )
      )

In "server.r" i do this:

output$continentCheckbox <- renderUI({
      checkboxGroupInput("continent", "choce continent:",choices = c("Europe", "Asia", "Africa"))
  })

EDIT: this is a minimal app code:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "FlightAnalyzer"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("conPanelTest", tabName = "3dGlobe", icon = icon("globe"))
    )
  ),
  dashboardBody(
    tabItems(
      tabItem( tabName = "3dGlobe",
               fluidRow(
                 column( width = 4,
                           radioButtons("filters", "Filters" , choiceNames = list("All","Some continents") , choiceValues = list("all","continent")),
                           conditionalPanel(
                             condition = "filters == 'continent'",
                             uiOutput("continentCheckbox")
                           )
                 )
               )
      )
      
    )
    
  )
)



server <- function(input, output) {
  output$continentCheckbox <- renderUI({
    checkboxGroupInput("continentCheckbox ", "Seleziona il Continente:",choices = c("Europa", "Asia", "Africa", "Americhe", "Oceania"))
    
  })
  
}




shinyApp(ui = ui, server = server)

xSambx02
  • 25
  • 7
  • I can't reproduce your issue. When I copy your code into a minimal app it works fine and conditionally shows `continentCheckbox` (or actually radioButtons) when "continent" is selected in the input `filters`. Perhaps you could clarify what's the issue and provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a minimal working app code which others could run. – stefan Mar 13 '23 at 10:49
  • @stefan the problem is that the app never shows the "continent" radioButtons – xSambx02 Mar 13 '23 at 11:01
  • Okay. But as I said: When I copy your code in a minimal shiny app they show up. Hence, as is your issue is not reproducible. – stefan Mar 13 '23 at 11:10
  • @stefan what can be the problem in your opinion? – xSambx02 Mar 13 '23 at 11:13
  • 1
    @stefan can't reproduce yopur problem. You haven't given us a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). So the problem *must* lie in some part of your code (or set up) that you haven't shown us. We can only speculate. – Limey Mar 13 '23 at 11:31
  • @stefan i added a minimal code. Tell me if it works in your pc, for me it never shows the checkboxes ... – xSambx02 Mar 13 '23 at 13:05
  • The issue is that you use `condition = "filters == 'continent'"` instead of `condition = "input.filters == 'continent'"` . – stefan Mar 13 '23 at 13:09
  • @stefan has identified one problem with your code. The other is that you have two output widgets names `continentCheckbox`: the UI in your conditional panel, and the `radioButtons` it creates. Fix the two problems and you should be fine. (You can also drop the `uiOutput` completely and place the`continentCheckbox` `radioButtons` directly inside the conditional panel.) – Limey Mar 13 '23 at 13:13
  • comment out `submitButton()` and us `condition = "input.filters == 'all'",` – YBS Mar 13 '23 at 15:04
  • @YBS wtf now it works ... why the submitButton affects that conditionalPanel? – xSambx02 Mar 13 '23 at 15:39
  • I am not sure. You can use `actionButton` instead. – YBS Mar 13 '23 at 15:50

1 Answers1

1

Here's a MRE that I believe behaves as you expect after correcting the problems mentioned by @stefan and myself.

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "FlightAnalyzer"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("conPanelTest", tabName = "3dGlobe", icon = icon("globe"))
    )
  ),
  dashboardBody(
    tabItems(
      tabItem( 
        tabName = "3dGlobe",
        fluidRow(
          column( 
            width = 4,
            radioButtons(
              "filters", 
              "Filters" , 
              choiceNames = list("All","Some continents"), 
              choiceValues = list("all","continent")
            ),
            conditionalPanel(
              condition = "input.filters == 'continent'",
              radioButtons(
                "continentCheckboxUI", 
                "Seleziona il Continente:",
                choices = c("Europa", "Asia", "Africa", "Americhe", "Oceania")
              )
            )
          )
        )
      )
    )
  )
)

server <- function(input, output) {}

shinyApp(ui = ui, server = server)

enter image description here

Limey
  • 10,234
  • 2
  • 12
  • 32
  • it doesn't work the same... but now i noticed that in R console i get this error: "Ignoring explicitly provided widget ID "57qnppgd7Q"; Shiny doesn't use them" . It can be the problem? – xSambx02 Mar 13 '23 at 13:24
  • I've demonstrated that my code works. If it doesn't work for you, it must be because of a situation that you have and I don't. I can only suggest restrating your R session (closing down R Studio if that's what you're using) and checking that your packages are up to date. – Limey Mar 13 '23 at 13:27
  • the problem is that also the code you provided doesn't work for me ... i can't understand why ... i simply copied and pasted it – xSambx02 Mar 13 '23 at 13:31
  • Did you restart R? Did you update your packages? Simply copying and pasting in a situation like this is not sufficient. If you did all that and you still have the problem, then, alas, the problem is not reproducible and therefore unlikely to be answerable on SO. – Limey Mar 13 '23 at 13:34
  • yes i have all the packages updated and i also tried to reboot rstudio – xSambx02 Mar 13 '23 at 13:36