Package 'dragulaR'

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

Help Index


Register containers to dragula.

Description

Create dragula instace to allow moving around elements of the registered containers.

Usage

dragula(x, ...)

Arguments

x

vector of containers ids. Their's elements will become draggable.

...

additonal arguments passed to dragula JS as options. E.g. id will be an id to read from in shiny. Additional shortcut options:

  • copyOnly: container id from which elements can only be copied (not moved)

  • maxItems: named list specifying maximum items per container, e.g. maxItems = list(Model = 3)

Value

Return htmlWidget. Should be used only inside shiny ui.

Examples

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)

Dragula widget.

Description

Create dragula widget.

Usage

dragulaOutput(outputId)

renderDragula(expr, env = parent.frame(), quoted = FALSE)

Arguments

outputId

output variable to read from.

expr

An expression that generates a dragula object.

env

The environment in which to evaluate expr.

quoted

Is expr a quoted expression (with quote())? This is useful if you want to save an expression in a variable.

Value

dragulaOutput returns a Shiny tag list for the UI. renderDragula returns a Shiny render function for the server.

Examples

if(interactive()) {
  path <- system.file("apps/example02-input", package = "dragulaR")
  runApp(path, display.mode = "showcase")
}

Format dragula input object.

Description

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.

Usage

dragulaValue(x)

Arguments

x

dragula input.

Value

A named list where names are container IDs and values are character vectors of element identifiers (from the drag attribute).

Examples

## Not run: 
# Example call:
dragulaValue(input$dragula)

## End(Not run)

Register dragulaR's js functions for refreshing dragula object.

Description

This function enables the js$refreshDragulaR() JavaScript function in Shiny, which should be called after dynamically adding elements to a dragula container.

Usage

useDragulajs()

Value

A Shiny tag list that registers the JavaScript extension.

Examples

## 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)