View source: R/draggable_buckets.R
draggable_buckets | R Documentation |
A custom widget with draggable elements that can be put into buckets.
draggable_buckets(input_id, label, elements = character(), buckets)
input_id |
( |
label |
( |
elements |
( |
buckets |
( |
shinyvalidate
validation can be used with this widget. See example below.
the HTML
code comprising an instance of this widget
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.