在单选按钮中选择数字时设置条件

Set condition when numbers are chosen in radioButtons

我想只在为三个 radioButtons 选择值时显示条件,无论选项如何。实际上,我只是选择了一个选项,并且已经出现了这种情况,但这不是我想要的。我将其保留为 '2' em "input.radio1 == '2',但仅作为示例,想法是它对任何选定值都有效。

下面的可执行代码:

library(shiny)
library(shinythemes)


ui <- bootstrapPage(
  navbarPage(theme = shinytheme("flatly"), collapsible = TRUE,
             "Cl", 
             tabPanel("Solution",
                      
                      sidebarLayout(
                        sidebarPanel(
                          
                          radioButtons("radio1", label = h3("Choose 1"),
                                       choices = list("Option1" = 2, "Option2" = 3, "Option3" = 4), 
                                       selected = ""),
                          
                          radioButtons("radio2", label = h3("Choose 2"),
                                       choices = list("Option4" = 2, "3 clusters" = 3, "Option5" = 4), 
                                       selected = ""),
                          
                          radioButtons("radio3", label = h3("Choose 3"),
                                       choices = list("Option6" = 2, "Option1" = 3, "Option8" = 4), 
                                       selected = ""),
                          
                          conditionalPanel(
                            condition = "input.radio1 == '2'|| input.radio2 == '2'|| input.radio3 == '2'",
                            
                            tags$hr(style="border-color: black;"),
                            tags$p(h3("Are you satisfied with this solution?")),
                            radioButtons( "satisfaction","", choices = list("Yes" = 1,"Not " = 2),selected = 1))
                        ),
                        mainPanel(
                          tabsetPanel(      
                          )))
                      
             )))

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

shinyApp(ui = ui, server = server)  

更新

据我所知,您必须在 condition 中使用 && 而不是 ||。现在我只需要调整问题,它可以是 radiobutton1radiobutton2radiobutton3 中的任意选择,而不仅仅是选项 2.

有了这个 condition = "input.radio1 && input.radio2 && input.radio3",仅当用户为所有 3 个单选按钮都选择了一个选项时,才应显示条件面板。