嗨,乐于助人的 R 社区,
问题:我有两个不同类型的组织的列表pickerInputs
-list_1
和list_2
. 我想强制用户从两个列表中至少选择 5 个(例如他们可以从 3 个组织list_1
和 2 个组织中选择list_2
)。当他们选择至少 5 个组织时,我想在 mainPanel 中渲染他们选择的内容。如果他们没有选择至少 5 个组织,我希望消息是“请选择至少 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)