Usage
draggable_buckets(input_id, label, elements = character(), buckets)
Arguments
- input_id
(
character(1)
) theHTML
id of this widget- label
(
character(1)
orshiny.tag
) the header of this widget- elements
(
character
) the elements to drag into buckets- buckets
(
character
orlist
) the names of the buckets the elements can be put in or a list of key-pair values where key is a name of a bucket and value is a character vector of elements in a bucket
Examples
ui <- shiny::fluidPage(
draggable_buckets("id", "Choices #1", c("a", "b"), c("bucket1", "bucket2")),
draggable_buckets("id2", "Choices #2", letters, c("vowels", "consonants")),
shiny::verbatimTextOutput("out"),
shiny::verbatimTextOutput("out2")
)
server <- function(input, output) {
iv <- shinyvalidate::InputValidator$new()
iv$add_rule(
"id",
function(data) if (length(data[["bucket1"]]) == 0) "There should be stuff in bucket 1"
)
iv$enable()
shiny::observeEvent(list(input$id, input$id2), {
print(isolate(input$id))
print(isolate(input$id2))
})
output$out <- shiny::renderPrint({
iv$is_valid()
input$id
})
output$out2 <- shiny::renderPrint(input$id2)
}
if (interactive()) shiny::shinyApp(ui, server)
# With default elements in the bucket
ui <- shiny::fluidPage(
draggable_buckets("id", "Choices #1", c("a", "b"), list(bucket1 = character(), bucket2 = c("c"))),
shiny::verbatimTextOutput("out")
)
server <- function(input, output) {
shiny::observeEvent(input$id, {
print(shiny::isolate(input$id))
})
output$out <- shiny::renderPrint(input$id)
}
if (interactive()) shiny::shinyApp(ui, server)