Im trying to limit the max number of choices made by pickerInput()
to two in shiny
app but I cannot make it work.
library(shiny)
library(shinydashboard)
library(plotly)
library(shinyWidgets)
header <- dashboardHeader()
sidebar <- dashboardSidebar(
fluidRow(column(12,
pickerInput(
inputId = "iss",
label = "Issue",
choices = colnames(mtcars),
multiple = T,
options = list("max-options-group" = 2)
)
))
)
body <- dashboardBody(fluidPage(
)
)
ui <- dashboardPage(title = 'Search', header, sidebar, body)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
CodePudding user response:
The problem is that you are using "max-options-group"
but you are not using any groups in your choices
. You must use "max-options" = 2
in the options
argument of pickerInput()
.
For completeness, this is the modified version of your code. We cannot pick more than 2 options with it:
library(shiny)
library(shinydashboard)
library(plotly)
library(shinyWidgets)
header <- dashboardHeader()
sidebar <- dashboardSidebar(
fluidRow(column(12,
pickerInput(
inputId = "iss",
label = "Issue",
choices = colnames(mtcars),
multiple = T,
options = list("max-options" = 2)
)
))
)
body <- dashboardBody(fluidPage(
)
)
ui <- dashboardPage(title = 'Search', header, sidebar, body)
server <- function(input, output, session) {
}
shinyApp(ui = ui, server = server)
CodePudding user response:
Try this
columns <- as.list(names(mtcars))
type <- as.list(1:ncol(mtcars))
header <- dashboardHeader()
sidebar <- dashboardSidebar(
fluidRow(column(12,
pickerInput(
inputId = "iss",
label = "Issue",
choices = list(Columns = columns,
Type = type),
selected = list(columns[[1]],type[[1]]),
multiple = T,
inline=TRUE,
options = list("max-options-group" = 1, `style` = "btn-info")
)
))
)
body <- dashboardBody(fluidPage())
ui <- dashboardPage(title = 'Search', header, sidebar, body)
server <- function(input, output, session) {}
shinyApp(ui = ui, server = server)