3

I'm working on a basic Shiny UI template where the user has to pick a certain button in order to give the app input. Right now I'm using a conditionalPanel() but instead of the input buttons going away completely, is it possible to gray them out?

Here's the following code:

  library(shiny)
  library(shinyjs)
 ui<-fluidPage(

 headerPanel("Title"),
 sidebarPanel(
 radioButtons("toggle", "Some Buttons",
             choices = list("Choice 1" = 1,
                           "Choice 2" = 2),
            selected = "Choice 2")),
conditionalPanel(
 condition = "input.toggle % 2 == 0",
 sidebarPanel(radioButtons("otherButtons","Buttons",
              choices = list("Choice 1"=1,
                            "Choice 2"=2)),
 radioButtons("moreButtons","Buttons",
              choices = list("Choice 1"= 1,
                            "Choice 2" = 2))
  ),
  "Some Text"
 )


 )




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



 }

shinyApp(ui,server)
Colin
  • 47
  • 3
  • maybe [library(shinyjs)](https://stackoverflow.com/questions/19611254/r-shiny-disable-able-shinyui-elements) can help you? – Nate Jun 08 '18 at 01:30

1 Answers1

2

Maybe you could try this. You won't be able to select anything in the second panel when you pick Choice 1 in the first panel.

ui <- fluidPage(

  headerPanel("Title"), shinyjs::useShinyjs(),

  sidebarPanel(id = "mySideBar",
               radioButtons("toggle", "Some Buttons",
                            choices = list("Choice 1" = 1,
                                           "Choice 2" = 2),
                            selected = "Choice 2")),

      sidebarPanel(id = "mySideBar2",
        radioButtons("otherButtons","Buttons",
                                choices = list("Choice 1"=1,
                                               "Choice 2"=2)),
                   radioButtons("moreButtons","Buttons",
                                choices = list("Choice 1"= 1,
                                               "Choice 2" = 2))

)   
)


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

  shinyjs::onclick("advanced2",
                   shinyjs::toggle(id = "advanced2", anim = TRUE))

  observeEvent(input$toggle, {
    if(input$toggle == "1"){
      shinyjs::disable(id = "mySideBar2")
    } else {
      shinyjs::enable(id = "mySideBar2")
    }
  })

}

shinyApp(ui,server)
MLavoie
  • 9,671
  • 41
  • 36
  • 56