Limitar o número possível de seleções em um Input

Fala galera, blz?

Seguinte tenho o seguinte exemplo de programa para vcs onde eu queria que o usuário conseguisse escolher no MÁX 5 Countrys para ser mostrado por vez na tabela e depois ele poder exportar essa tabela com o max de 5 elementos, deve ser algo beem bobo mas eu n achei em nenhum fórum como fazer isso =( HELP!!

    library(shiny)
    library(dplyr)

    Country <- c("USA", "Mexico", "Canada", "China", "Vietnam", "India", "France", "Germany", "Poland")
    Region <- c("Americas", "Americas", "Americas", "Asia", "Asia", "Asia", "Europe", "Europe", "Europe")
    Product <- c(11, 22, 33, 44, 55, 66, 77, 88, 99)
    Date <- c(1, 2, 3, 4, 5, 6, 7, 8, 9)
    DF <- cbind(Region, Country, Product, Date)
    DF <- as.data.frame(DF)

    Region <- as.factor(sort(unique(DF$Region)))
    Country <- as.factor(sort(unique(DF$Country)))

    ui <- fluidPage(titlePanel("Filtering experiments"),
                    sidebarLayout(
                      # Sidebar panel for inputs ----
                      sidebarPanel(
                        width = 3,
                        selectizeInput(
                          "CountrySelect",
                          "Country",
                          Country,
                          selected = NULL,
                          multiple = TRUE
                        )
                      ),

                      # Main panel for displaying outputs ----
                      mainPanel(fluidPage(
                        width = 12, tableOutput("table")
                      ))
                    ))

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

      observeEvent(input$RegionSelect, {
        req(input$RegionSelect)
        test <- DF %>%
          filter(Region %in% input$RegionSelect) %>%
          select(Country)

        updateSelectizeInput(session, 
                             inputId = "CountrySelect",
                             choices = test)
      })

      output$table <- renderTable({
        # Uncomment the two lines with comments if you want to make it mandatory to chose a continent to show the table

        # req(input$RegionSelect)
        req(input$CountrySelect)
        DF %>%
          # filter(Region %in% input$RegionSelect) %>%
          filter(Country %in% input$CountrySelect)
      })}
    shinyApp(ui, server)

RESOLVIDO!!!

options = list(maxItems = 10) é só colocar isto como parâmetro dentro do input

1 curtida