| Title: | Drag and Drop Elements in 'Shiny' using 'Dragula Javascript Library' |
|---|---|
| Description: | Move elements between containers in 'Shiny' without explicitly using 'JavaScript'. It can be used to build custom inputs or to change the positions of user interface elements like plots or tables. |
| Authors: | Nicolas Bevacqua [aut, cph] (dragula library in htmlwidgets/lib, https://github.com/bevacqua/dragula), Zygmunt Zawadzki [aut, cre] (R interface), Darren Maczka [ctb] |
| Maintainer: | Zygmunt Zawadzki <[email protected]> |
| License: | GPL-2 |
| Version: | 0.3.3 |
| Built: | 2026-05-17 08:16:46 UTC |
| Source: | https://github.com/zzawadz/dragular |
Create dragula instace to allow moving around elements of the registered containers.
dragula(x, ...)dragula(x, ...)
x |
vector of containers ids. Their's elements will become draggable. |
... |
additonal arguments passed to dragula JS as options. E.g.
|
Return htmlWidget. Should be used only inside shiny ui.
if(interactive()) { # Basic example path <- system.file("apps/example01-dragula", package = "dragulaR") runApp(path, display.mode = "showcase") # Example with maxItems (limits Model container to 3 items) path <- system.file("apps/example08-max-items", package = "dragulaR") runApp(path, display.mode = "showcase") } # Create dragula with maxItems limit ## Not run: dragula(c("Available", "Model"), maxItems = list(Model = 3)) ## End(Not run)if(interactive()) { # Basic example path <- system.file("apps/example01-dragula", package = "dragulaR") runApp(path, display.mode = "showcase") # Example with maxItems (limits Model container to 3 items) path <- system.file("apps/example08-max-items", package = "dragulaR") runApp(path, display.mode = "showcase") } # Create dragula with maxItems limit ## Not run: dragula(c("Available", "Model"), maxItems = list(Model = 3)) ## End(Not run)
Create dragula widget.
dragulaOutput(outputId) renderDragula(expr, env = parent.frame(), quoted = FALSE)dragulaOutput(outputId) renderDragula(expr, env = parent.frame(), quoted = FALSE)
outputId |
output variable to read from. |
expr |
An expression that generates a dragula object. |
env |
The environment in which to evaluate |
quoted |
Is |
dragulaOutput returns a Shiny tag list for the UI.
renderDragula returns a Shiny render function for the server.
if(interactive()) { path <- system.file("apps/example02-input", package = "dragulaR") runApp(path, display.mode = "showcase") }if(interactive()) { path <- system.file("apps/example02-input", package = "dragulaR") runApp(path, display.mode = "showcase") }
This is a utility function for better formatting dragula's input. It extracts the container names and their element order from the raw input object.
dragulaValue(x)dragulaValue(x)
x |
dragula input. |
A named list where names are container IDs and values are
character vectors of element identifiers (from the drag attribute).
## Not run: # Example call: dragulaValue(input$dragula) ## End(Not run)## Not run: # Example call: dragulaValue(input$dragula) ## End(Not run)
This function enables the js$refreshDragulaR() JavaScript function
in Shiny, which should be called after dynamically adding elements to
a dragula container.
useDragulajs()useDragulajs()
A Shiny tag list that registers the JavaScript extension.
## Not run: # See example for more details library(dragulaR) runApp( system.file("apps/example05-dragula-dynamic-elements", package = "dragulaR"), display.mode = "showcase") ## End(Not run)## Not run: # See example for more details library(dragulaR) runApp( system.file("apps/example05-dragula-dynamic-elements", package = "dragulaR"), display.mode = "showcase") ## End(Not run)