--- title: "Understanding the interface to sortable.js" author: "Andrie de Vries and Kenton Russell" date: "`r Sys.Date()`" output: rmarkdown::html_vignette description: > Understanding the key idea of `sortable.js` will help you to write your own custom sortable widgets. vignette: > %\VignetteIndexEntry{Understanding the interface to sortable.js} %\VignetteEngine{knitr::rmarkdown} %\usepackage[utf8]{inputenc} --- ```{r, echo = FALSE} ## get knitr just the way we like it knitr::opts_chunk$set( message = FALSE, warning = FALSE, error = FALSE, tidy = FALSE, cache = FALSE ) ``` ```{css, echo=FALSE} pre { max-height: 20em; overflow-y: auto; } pre[class] { max-height: 20em; } ``` With the `sortable` [`htmlwidget`](http://www.htmlwidgets.org) you can use powerful, dependency-free interactivity from [`SortableJS`](https://sortablejs.github.io/Sortable/) in the browser, RStudio Viewer, or Shiny apps. ```{r} library(sortable) library(htmltools) ``` ## The central idea The key idea to understand about `sortable`, and `SortableJS` in particular, is that the JavaScript will manipulate an HTML object based on it's CSS `id`. Using `sortable` in markdown is a little tricky since markdown does not provide an easy way to provide an `id` that we'll need. We can overcome this by using bare `HTML` or using `htmltools::tags`. Let's make a simple `ul` list. Note, however, that `sortable` works with nearly any `HTML` element, such as `div`. ### An example using raw HTML The following example uses HTML to construct an unordered list (`