-
|
In the documentation there's an example of a dropdown which options have headers and a divider. How can this be implemented using library(shiny)
library(shiny.fluent)
ui <- fluentPage(
Dropdown(
"dropdown",
label = "Test multiple",
multiSelect = TRUE,
options = list(
list(key = "fruitsHeader", text = "Fruits", itemType = "DropdownMenuItemType.Header"),
list(key = "apple", text = "Apple" ),
list(key = "banana", text = "Banana" ),
list(key = "orange", text = "Orange", disabled = TRUE),
list(key = "grape", text = "Grape" ),
list(key = "divider_1", text = "-", itemType = "DropdownMenuItemType.Divider"),
list(key = "vegetablesHeader", text = "Vegetables", itemType = "DropdownMenuItemType.Header"),
list(key = "broccoli", text = "Broccoli" ),
list(key = "carrot", text = "Carrot" ),
list(key = "lettuce", text = "Lettuce" )
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
|
Beta Was this translation helpful? Give feedback.
Answered by
jakubsob
Apr 5, 2022
Replies: 1 comment
-
|
Header and Divider are enums, not strings. In order for Header and Divider to appear we need to import them from Fluent module. We can create a helper function library(shiny)
library(shiny.fluent)
DropdownMenuItemType <- function(type) {
JS(paste0("jsmodule['@fluentui/react'].DropdownMenuItemType."), type)
}
ui <- fluentPage(
Dropdown(
"dropdown",
label = "Test multiple",
multiSelect = TRUE,
options = list(
list(key = "fruitsHeader", text = "Fruits", itemType = DropdownMenuItemType("Header")),
list(key = "apple", text = "Apple" ),
list(key = "banana", text = "Banana" ),
list(key = "orange", text = "Orange", disabled = TRUE),
list(key = "grape", text = "Grape" ),
list(key = "divider_1", text = "-", itemType = DropdownMenuItemType("Divider")),
list(key = "vegetablesHeader", text = "Vegetables", itemType = DropdownMenuItemType("Header")),
list(key = "broccoli", text = "Broccoli" ),
list(key = "carrot", text = "Carrot" ),
list(key = "lettuce", text = "Lettuce" )
)
)
)
server <- function(input, output, session) {
}
shinyApp(ui, server)
|
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
jakubsob
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Header and Divider are enums, not strings. In order for Header and Divider to appear we need to import them from Fluent module. We can create a helper function
DropdownMenuItemTypewhich accesses the desired field: