有什么方法可以根据条件使 Shiny 中的面板变灰?
Any way to grey panels out in Shiny based on a conditional?
我正在开发一个基本的 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)
也许你可以试试这个。当您在第一个面板中选择选项 1 时,您将无法 select 在第二个面板中进行任何操作。
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)
我正在开发一个基本的 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)
也许你可以试试这个。当您在第一个面板中选择选项 1 时,您将无法 select 在第二个面板中进行任何操作。
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)