【问题标题】:Any way to grey panels out in Shiny based on a conditional?有什么方法可以根据条件在 Shiny 中将面板变灰?
【发布时间】:2018-06-08 19:26:08
【问题描述】:

我正在开发一个基本的 Shiny UI 模板,用户必须选择某个按钮才能给应用程序输入。现在我正在使用 conditionalPanel() 但不是输入按钮完全消失,是否可以将它们变灰?

下面是代码:

  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)

【问题讨论】:

标签: r shiny shinyjs


【解决方案1】:

也许你可以试试这个。当您在第一个面板中选择选项 1 时,您将无法在第二个面板中选择任何内容。

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)

【讨论】:

  • @Albert,如果答案适合你,请接受我的回答。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-11-05
  • 2021-04-09
  • 2015-10-28
  • 2016-08-14
  • 2016-06-04
  • 2021-01-02
  • 1970-01-01
相关资源
最近更新 更多