This article describes how to apply rules to drag-and-drop tables, many R tables*, and visualizations (with tests) in Displayr (not R-based visualizations). Rules are a set of predefined automated functions – most commonly, they could be thought of as a way of conditionally formatting tables (where you specify the conditions). However the range of available functions extends well beyond formatting. The current library of automated options includes (but is not limited to):
- Highlighting cells or chart series via custom criteria (e.g., ranges, greater/less than, top n).
- Applying color scales to entire tables or charts.
- Adding text, symbols to table cells or chart data labels.
- Customizing significance comparisons.
- Removing rows or columns or hiding cells based in specific criteria (e.g., minimum sample size).
- Reformatting columns (e.g., include sample size; re-label but leave source variable intact).
- Customizing footers.
- Automatically re-sorting charts or tables, by columns or rows of your choice.
- Weighting selected columns or rows.
*Not all rules are currently compatible with R tables. Incompatible rules will display a warning in the RULES field and in the Rule's pop-up window (if available). See: Caveats and Limitations for Rules for more information.
Requirements
Please note this requires the Data Stories module or a Displayr license.
Not all rules are avaialble for use in Data Stories
Method - Apply rules
- To apply a rule, simply select your table and click the Plus (+) button under the RULES section of the Properties tab in the object inspector.
- The selected rule will then be added to the RULES field box.
- You are able to add multiple rules to your table. Note, the rules will be applied in the order they appear in this box. Depending on the rules being used, you may need to change the order via dragging one above the other to ensure they work as intended. For example, if you wish to shade table cells but also want to remove values under a specific value, you would need to apply the shading cells rule first.
- To automatically apply this rule to all new tables, right-click the rule and tick Use for new table and charts.
- To add this rule to all existing tables, right-click and select Apply > Add to every item in the document.
- To add this rule to all selected tables, right-click and select Apply > Add to selected items.
- Note that changing the dimensions of a table by, for example, using the Switch rows and columns option will affect the implementation of the rule. You may then need to apply an alternate rule if it is specific to rows or columns.
Method - Edit rules
- To edit rules, right-click the appropriate rule in the object inspector and select Edit.
- OPTIONAL: Select Edit JavaScript to customize the underlying code further. Note, Highlight Cells, Top/Bottom and Color Scale Rules cannot be modified in this way.
- Change the necessary settings and press OK.
Method - Delete rules
-
To delete rules, right-click the appropriate rule in the object inspector > Delete. Note, if you have applied this rule to all tables in one step (as opposed to doing so individually) or have copied a table with the rule already applied, this option will delete it from all tables that use this rule. You can highlight which tables are connected by this rule by selecting the Show all tables using this rule option.
- Alternatively, you can delete the rule from all existing tables by right-clicking and selecting Apply > Remove from every item in the document.
- To only remove the rule from selected tables, right-click and select Apply > Remove from selected items.
Method - Custom rules
All the rules are written in JavaScript (see Table JavaScript and Plot JavaScript for details). You can write your own rules in JavaScript, applying them by selecting New custom rule (write your own JavaScript). See How to Create a Custom Rule and How to Customize a Rule for more information.