强制用户 select 至少 n 个来自 pickerInput 的选项(R 闪亮)?

Force user to select at least n number of options from pickerInput (R shiny)?

嗨有用的 R 社区,

问题: 我在两个不同的 pickerInputs- list_1list_2 中有两种不同类型的组织的列表。我想强制用户从两个列表中 select 总共 最少 5 个 (例如他们可以 select 来自 list_1 的 3 个组织和 2 个组织来自 list_2)。当他们 select 至少 5 个组织时,我想在 mainPanel 中渲染文本,打印他们 selected 的内容。如果他们还没有 selected 至少 5 个组织,我希望消息是“请 select 至少 5 个组织继续!”

这是一个代表:

# LIBRARIES ----
library(shiny)
library(shinyWidgets)
library(glue)



# USER INTERFACE ----
ui <- fluidPage(
  
  sidebarLayout(
    sidebarPanel = sidebarPanel(
      width = 4,
      p("Peer Group Comparisons"),
      
      pickerInput(
        inputId  = "list_1",
        label    = "Organizations from List 1",
        choices  = c("a", "b", "c", "d"),
        options  = pickerOptions(
          actionsBox = TRUE,
          liveSearch = TRUE),
           multiple = TRUE 
      ),
      pickerInput(
        inputId  = "list_2",
        label    = "Organizations from List 2",
        choices  = c("e", "f", "g", "h", "x", "y", "z"),
        options  = pickerOptions(
          actionsBox = TRUE,
          liveSearch = TRUE),
        multiple = TRUE 
      )
      ),
      
     
      mainPanel = mainPanel(width = 8,
                            textOutput("results")
      )
      
    )
    
  )
  
  
  # SERVER ----
  server <- function(input, output, session) {
    
    output$list1_and_list2 <- reactive({
      glue(input$list1, input$list2)
    })
    
    output$results <- renderText(
      list1_and_list2() 
    )
  }
  
  shinyApp(ui, server)
library(shiny)
library(shinyWidgets)
library(glue)



# USER INTERFACE ----
ui <- fluidPage(

sidebarLayout(
    sidebarPanel = sidebarPanel(
        width = 4,
        p("Peer Group Comparisons"),
        
        pickerInput(
            inputId  = "list_1",
            label    = "Organizations from List 1",
            choices  = c("a", "b", "c", "d"),
            options  = pickerOptions(
                actionsBox = TRUE,
                liveSearch = TRUE),
            multiple = TRUE 
        ),
        pickerInput(
            inputId  = "list_2",
            label    = "Organizations from List 2",
            choices  = c("e", "f", "g", "h", "x", "y", "z"),
            options  = pickerOptions(
                actionsBox = TRUE,
                liveSearch = TRUE),
            multiple = TRUE 
        )
    ),
    
    
    mainPanel = mainPanel(width = 8,
                          textOutput("results")
    )
    
)

)


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

output$results <- renderText(
          if(length(c(input$list_1, input$list_2))<5) {
         "Please select a minimum of 5 organizations to proceed!"
          } else {
            c(input$list_1, input$list_2)
          }
 
)
}

shinyApp(ui=ui, server=server)