orderInput: Create a shiny input control to show the order of a set of...

Description Usage Arguments Details Value Examples

View source: R/orderInput.R

Description

Display a set of items whose order can be changed by drag and drop inside or between orderInput(s). The item order is send back to server in the from of input$inputId.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
orderInput(
  inputId,
  label,
  items,
  as_source = FALSE,
  connect = NULL,
  item_class = c("default", "primary", "success", "info", "warning", "danger"),
  placeholder = NULL,
  width = "500px",
  legacy = FALSE,
  ...
)

Arguments

inputId

The input slot that will be used to access the current order of items.

label

Display label for the control, or NULL for no label.

items

Items to display, can be a list, an atomic vector or a factor. For list or atomic vector, if named, the names are displayed and the order is given in values. For factor, values are displayed and the order is given in levels

as_source

A boolean value to determine whether the orderInput is set as source mode. Only works if the connect argument was set.

connect

Optional. Allow items to be dragged between orderInputs. Should be a vector of inputId(s) of other orderInput(s) that the items from this orderInput should be connected to.

item_class

One of the Bootstrap color utility classes to apply to each item.

placeholder

A character string to show when there is no item left in the orderInput.

width

The width of the input, e.g. '400px', or '100\ shiny::validateCssUnit.

legacy

A boolean value. Whether to use the old version of the orderInput function.

...

Arguments passed to shiny::tags$div which is used to build the container of the orderInput.

Details

orderInputs can work in either connected mode or stand-alone mode. In stand-alone mode, items can only be drag and drop inside the input control. In connected mode, items to be dragged between orderInputs, which is controlled by the connect parameter. This is a one-way relationship. if user want the items to be connected in both directions, the connect parameter must be set on both orderInputs.

When in connected mode, orderInput can be set as source-only through the as_source parameter. The items in a "source" orderInput can only be copied, instead of moved, to other connected non-source orderInput(s). From shinyjqui v0.4.0, A "source" orderInput will become a "recycle bin" for items from other orderInputs as well. This means, if you want to delete an item, you can drag and drop it into a "source" orderInput. This feature can be disabled by setting the options of non-source orderInput(s) as list(helper = "clone").

From shinyjqui v0.4.0 and above, the orderInput function was implemented in the similar way as other classical shiny inputs, which brought two changes:

  1. The input value was changed from input$inputId_order to input$inputId;

  2. The new version supports updateOrderInput function which works in the same way as other shiny input updater functions. To keep the backward compatibility, a legacy argument was provided if user wanted to use the old version.

Value

An orderInput control that can be added to a UI definition.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
orderInput('items1', 'Items1', items = month.abb, item_class = 'info')

## build connections between orderInputs
orderInput('items2', 'Items2 (can be moved to Items1 and Items4)', items = month.abb,
           connect = c('items1', 'items4'), item_class = 'primary')

## build connections in source mode
orderInput('items3', 'Items3 (can be copied to Items2 and Items4)', items = month.abb,
           as_source = TRUE, connect = c('items2', 'items4'), item_class = 'success')

## show placeholder
orderInput('items4', 'Items4 (can be moved to Items2)', items = NULL, connect = 'items2',
           placeholder = 'Drag items here...')

Example output

<label for="items1">Items1</label>
<div id="items1" style="width: 500px; font-size: 0px; min-height: 25px;">
  <div data-value="Jan" class="btn btn-info" style="margin: 1px">Jan</div>
  <div data-value="Feb" class="btn btn-info" style="margin: 1px">Feb</div>
  <div data-value="Mar" class="btn btn-info" style="margin: 1px">Mar</div>
  <div data-value="Apr" class="btn btn-info" style="margin: 1px">Apr</div>
  <div data-value="May" class="btn btn-info" style="margin: 1px">May</div>
  <div data-value="Jun" class="btn btn-info" style="margin: 1px">Jun</div>
  <div data-value="Jul" class="btn btn-info" style="margin: 1px">Jul</div>
  <div data-value="Aug" class="btn btn-info" style="margin: 1px">Aug</div>
  <div data-value="Sep" class="btn btn-info" style="margin: 1px">Sep</div>
  <div data-value="Oct" class="btn btn-info" style="margin: 1px">Oct</div>
  <div data-value="Nov" class="btn btn-info" style="margin: 1px">Nov</div>
  <div data-value="Dec" class="btn btn-info" style="margin: 1px">Dec</div>
</div>
<label for="items2">Items2 (can be moved to Items1 and Items4)</label>
<div id="items2" style="width: 500px; font-size: 0px; min-height: 25px;">
  <div data-value="Jan" class="btn btn-primary" style="margin: 1px">Jan</div>
  <div data-value="Feb" class="btn btn-primary" style="margin: 1px">Feb</div>
  <div data-value="Mar" class="btn btn-primary" style="margin: 1px">Mar</div>
  <div data-value="Apr" class="btn btn-primary" style="margin: 1px">Apr</div>
  <div data-value="May" class="btn btn-primary" style="margin: 1px">May</div>
  <div data-value="Jun" class="btn btn-primary" style="margin: 1px">Jun</div>
  <div data-value="Jul" class="btn btn-primary" style="margin: 1px">Jul</div>
  <div data-value="Aug" class="btn btn-primary" style="margin: 1px">Aug</div>
  <div data-value="Sep" class="btn btn-primary" style="margin: 1px">Sep</div>
  <div data-value="Oct" class="btn btn-primary" style="margin: 1px">Oct</div>
  <div data-value="Nov" class="btn btn-primary" style="margin: 1px">Nov</div>
  <div data-value="Dec" class="btn btn-primary" style="margin: 1px">Dec</div>
</div>
<label for="items3">Items3 (can be copied to Items2 and Items4)</label>
<div id="items3" style="width: 500px; font-size: 0px; min-height: 25px;">
  <div class="btn btn-success jqui-interaction-mK1PY9FG" data-value="Jan" style="margin: 1px">Jan</div>
  <div class="btn btn-success jqui-interaction-MYgbJA7F" data-value="Feb" style="margin: 1px">Feb</div>
  <div class="btn btn-success jqui-interaction-vsjg6AxV" data-value="Mar" style="margin: 1px">Mar</div>
  <div class="btn btn-success jqui-interaction-VKmvZ1Ux" data-value="Apr" style="margin: 1px">Apr</div>
  <div class="btn btn-success jqui-interaction-2rzZi3d6" data-value="May" style="margin: 1px">May</div>
  <div class="btn btn-success jqui-interaction-LW4E7amx" data-value="Jun" style="margin: 1px">Jun</div>
  <div class="btn btn-success jqui-interaction-jLRNFzWf" data-value="Jul" style="margin: 1px">Jul</div>
  <div class="btn btn-success jqui-interaction-7kmSMLgd" data-value="Aug" style="margin: 1px">Aug</div>
  <div class="btn btn-success jqui-interaction-4g7Bcq22" data-value="Sep" style="margin: 1px">Sep</div>
  <div class="btn btn-success jqui-interaction-qLR3aEQE" data-value="Oct" style="margin: 1px">Oct</div>
  <div class="btn btn-success jqui-interaction-otX5jY4d" data-value="Nov" style="margin: 1px">Nov</div>
  <div class="btn btn-success jqui-interaction-egyv0YqG" data-value="Dec" style="margin: 1px">Dec</div>
</div>
<label for="items4">Items4 (can be moved to Items2)</label>
<div id="items4" style="width: 500px; font-size: 0px; min-height: 25px;"></div>

shinyjqui documentation built on Feb. 23, 2021, 9:06 a.m.