【发布时间】:2021-11-30 12:15:27
【问题描述】:
您好,有帮助的 R 社区,
问题:我有两个不同的pickerInputs-list_1 和list_2 中的两种不同类型组织的列表。我想强制用户从两个列表中选择至少 5 个(例如,他们可以从 list_1 中选择 3 个组织,从 list_2 中选择 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)
【问题讨论】:
标签: r shiny conditional-statements selectinput pickerinput