How to Connect Filters to a Combo Box (Control)
Displayr allows you to create filters which can be applied to analyses to see different patterns in your data. However, you can also create filters that are directly connected to a combo box (control) on an online dashboard.
If you're not familiar with using filters in Displayr, you can read our introductory post here.
Step 1: Get your data into Displayr
Start by opening a document that contains a Data Set. In the rest of this post I use the demonstration data that comes with Displayr. You can access this data by logging in to Displayr and clicking on Demo data - Use this data to try out Displayr.
Step 2: Create the page to be filtered
Add whatever you wish to show on the page. I have just dragged the Age variable across to form a table, as shown below.
Step 3: Create the control
Press Insert > Control (More), and a control (a combo box), will appear in the middle of your screen, as shown below.
Step 4: Set the properties of the control
Select the control (as shown above). We can set up the control by selecting the objects in the Control tab of the Object Inspector. In my example, I've:
- Set the Item list as 18 to 24; 25 to 39; 30 to 34; 35 to 44; 45 to 54; 55 to 64; 65 or more. Take care to use a semicolon and to avoid making any typos. The categories here need to be identical to those in the variable that you wish to use to filter.
- Set Selection mode to Multiple Selection.
- Set Placholder to Select the age categories to filter.
- Formatted it in a ugly but obvious way, to illustrate the type of formatting you can do.
- Moved it up.
- Put a heading on the page.
Step 5: Creating the filter
Press Insert > New R > Numeric Variable (Variables), and:
- Set the Label to Age filter
- Check Usable as a filter
- Set the R CODE to Age %in% Combo.box, replacing Age with the name of the variable in your file that you are wanting to use to filter. If you have changed the name of your control, or, have multiple controls, you will need to replace Combo.box with the correct name.
If you are filtering with multiple response data the R code is rowSums(variable.set.name[, Combo.box, drop = FALSE]) > 0. This requires that the multiple response data (e.g., brands consumed in the past six months), has a separate variable for each alternative in the combo box, the labels align exactly, and the variable set is of structure Binary - Multi.
Step 6: Apply the filter to the items on the page
Select the items on the page that you wish to filter, and choose the filter you have just created in Object Inspector > Inputs > FILTERS & WEIGHT > Filter(s).
Step 7: Export your dashboard
Now press Export > Web Page, Snapshot and View, and your preferred options for the next two questions. You can now select categories from the combo box and the outputs on the page will automatically update.