inst/apps/example05-dragula-dynamic-elements/app.R

library(shiny)
library(dragulaR)
library(shinyjs)

ui <- fluidPage(
        useShinyjs(),
        useDragulajs(),
        titlePanel("Add new elements to container elements"),
        verbatimTextOutput("order"),
        actionButton("Add", label = "Add"),
        fluidRow(id = "elements",
                 div(id = "placeholder")),
        dragula("elements", id = "dragula")
)

server <- function(input, output) {

  output$order <- renderPrint({
    dragulaValue(input$dragula)
  })
  counter <- reactiveVal(0)

  observeEvent(input$Add, {
    id <- counter()
    element <- div(drag = id, tags$h3(paste("Element", id)))
    insertUI(selector = "#placeholder", where = "beforeBegin", ui = element, immediate = TRUE)
    counter(id + 1)
    js$refreshDragulaR("dragula")

  })

}

shinyApp(ui = ui, server = server)

Try the dragulaR package in your browser

Any scripts or data that you put into this service are public.

dragulaR documentation built on May 1, 2019, 7:55 p.m.