Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rstudio/sortable

R htmlwidget for Sortable.js
https://github.com/rstudio/sortable

htmlwidget r r-package

Last synced: 3 days ago
JSON representation

R htmlwidget for Sortable.js

Awesome Lists containing this project

README

        

---
output: github_document
format: gfm
default-image-extension: ""
---

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# sortable

[![CRAN status](https://www.r-pkg.org/badges/version/sortable)](https://CRAN.R-project.org/package=sortable)
[![CRAN RStudio mirror downloads](https://cranlogs.r-pkg.org/badges/sortable)](https://www.r-pkg.org/pkg/sortable)
[![R build status](https://github.com/rstudio/sortable/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rstudio/sortable/actions)
[![Codecov test coverage](https://codecov.io/gh/rstudio/sortable/branch/main/graph/badge.svg)](https://codecov.io/gh/rstudio/sortable?branch=main)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)

The `sortable` package enables drag-and-drop behaviour in your Shiny apps. It does this by exposing the functionality of the [SortableJS](https://sortablejs.github.io/Sortable/) JavaScript library as an [htmlwidget](http://www.htmlwidgets.org) in R, so you can use this in Shiny apps and widgets, `learnr` tutorials as well as R Markdown. In addition, provides a custom `learnr` question type - `question_rank()` that allows ranking questions with drag-and-drop.

## Installation

You can install the released version of sortable from [CRAN](https://CRAN.R-project.org) with:

```r
install.packages("sortable")
```

And the development version from [GitHub](https://github.com/rstudio/sortable) with:

```r
# install.packages("remotes")
remotes::install_github("rstudio/sortable")
```

## Examples

### Rank list

You can create a drag-and-drop input object in Shiny, using the `rank_list()` function.

```{r echo=FALSE, cache=FALSE}
knitr::read_chunk(
system.file("shiny/rank_list/app.R", package = "sortable")
)
```

```{r rank-list-app, eval=FALSE}
```

### Bucket list

With a bucket list you can have more than one rank lists in a single object. This can be useful for bucketing tasks, e.g. asking your students to classify objects into multiple categories.

```{r echo=FALSE, cache=FALSE}
knitr::read_chunk(
system.file("shiny/bucket_list/app.R", package = "sortable")
)
```

```{r bucket-list-app, eval=FALSE}
```

### Add drag-and-drop to any HTML element

You can also use `sortable_js()` to drag and drop other widgets:

```{r, eval=FALSE}
library(DiagrammeR)
library(htmltools)

html_print(tagList(
tags$p("You can drag and drop the diagrams to switch order:"),
tags$div(
id = "aUniqueId",
tags$div(
style = "border: solid 0.2em gray; float:left; margin: 5px",
mermaid("graph LR; S[SortableJS] -->|sortable| R ",
height = 250, width = 300)
),
tags$div(
style = "border: solid 0.2em gray; float:left; margin: 5px",
mermaid("graph TD; JavaScript -->|htmlwidgets| R ",
height = 250, width = 150)
)
),
sortable_js("aUniqueId") # the CSS id
))
```

## Related work

I learnt about the following related work after starting on `sortable`:

* The `esquisse` [package](https://github.com/dreamRs/esquisse):

> "The purpose of this add-in is to let you explore your data quickly to extract the information they hold. You can only create simple plots, you won't be able to use custom scales and all the power of ggplot2."

* There is also the `shinyjqui` [package](https://yang-tang.github.io/shinyjqui/):

> "An R wrapper for jQuery UI javascript library. It allows user to easily add interactions and animation effects to a shiny app."

* The `shinyDND` [package](https://cran.r-project.org/package=shinyDND):

> Adds functionality to create drag and drop div elements in shiny.