Skip to contents

f7SmartSelect is smarter than the classic f7Select, allows for choices filtering, ...

updateF7SmartSelect changes the value of a smart select input on the client.

Usage

f7SmartSelect(
  inputId,
  label,
  choices,
  selected = NULL,
  openIn = c("page", "sheet", "popup", "popover"),
  searchbar = TRUE,
  multiple = FALSE,
  maxlength = NULL,
  virtualList = FALSE,
  ...
)

updateF7SmartSelect(
  inputId,
  selected = NULL,
  choices = NULL,
  multiple = NULL,
  maxLength = NULL,
  ...,
  session = shiny::getDefaultReactiveDomain()
)

Arguments

inputId

The id of the input object.

label

Select input label.

choices

The new choices.

selected

The new value for the input.

openIn

Smart select type: either c("sheet", "popup", "popover"). Note that the search bar is only available when the type is popup.

searchbar

Whether to enable the search bar. TRUE by default.

multiple

Whether to allow multiple values.

maxlength

Maximum items to select when multiple is TRUE.

virtualList

Enable Virtual List for smart select if your select has a lot of options. Default to FALSE.

...

Parameters used to update the smart select, use same arguments as in f7SmartSelect.

maxLength

Maximum items to select when multiple is TRUE.

session

The Shiny session object, usually the default value will suffice.

Examples

# Smart select input
if (interactive()) {
library(shiny)
library(shinyMobile)

 shinyApp(
   ui = f7Page(
     title = "My app",
     f7SingleLayout(
       navbar = f7Navbar(title = "f7SmartSelect"),
       f7SmartSelect(
         inputId = "variable",
         label = "Choose a variable:",
         selected = "drat",
         choices = colnames(mtcars)[-1],
         openIn = "popup"
       ),
       tableOutput("data"),
       f7SmartSelect(
         inputId = "variable2",
         label = "Group variables:",
         choices = list(
          `East Coast` = list("NY", "NJ", "CT"),
          `West Coast` = list("WA", "OR", "CA"),
          `Midwest` = list("MN", "WI", "IA")
         ),
         openIn = "sheet"
       ),
       textOutput("var")
     )
   ),
   server = function(input, output) {
     output$var <- renderText(input$variable2)
     output$data <- renderTable({
       mtcars[, c("mpg", input$variable), drop = FALSE]
     }, rownames = TRUE)
   }
 )
}
# Update smart select
if (interactive()) {
 library(shiny)
 library(shinyMobile)

 shinyApp(
  ui = f7Page(
    title = "My app",
    f7SingleLayout(
      navbar = f7Navbar(title = "Update f7SmartSelect"),
      f7Button("updateSmartSelect", "Update Smart Select"),
      f7SmartSelect(
        inputId = "variable",
        label = "Choose a variable:",
        selected = "drat",
        choices = colnames(mtcars)[-1],
        openIn = "popup"
      ),
      tableOutput("data")
    )
  ),
  server = function(input, output, session) {
    output$data <- renderTable({
      mtcars[, c("mpg", input$variable), drop = FALSE]
    }, rownames = TRUE)

    observeEvent(input$updateSmartSelect, {
      updateF7SmartSelect(
        inputId = "variable",
        openIn = "sheet",
        selected = "hp",
        choices = c("hp", "gear"),
        multiple = TRUE,
        maxLength = 3
      )
    })
  }
 )
}