How to Connect Filters to a Combo Box (Control)
With Displayr, you can show different patterns in your data by applying filters to analyses. One way to do this is by creating filters that connect directly to a control box on an online dashboard. Combo box, list box, text box and date controls are available, but in this blog post, I will manually create a combo box and apply it as a filter. For a more automated way of creating control-based filters, see Easy Functions for Automating Filters and Rebasing. If you're not familiar with using filters in Displayr, you can read our introductory post here.
Step 1: Import your data
Start by opening a document that contains a Data Set. For this example, I used demonstration data from a brand tracking study.
Step 2: Create a table to be filtered
|Add whatever you wish to show on the page. I have dragged the Age variable across from the Data Sets panel to form a table.|
Step 3: Create the control
||Go to Insert > Control > Combo box to create the combo box. It will appear in the middle of your screen.|
Step 4: Set the control properties
||Select the control and click on the Control tab in the Object Inspector.
Make the following changes:
Step 5: Creating the filter
|Go to Insert > R > Numeric Variable. Make the following changes:
If you are using your own dataset, replace Age with the name of the variable you want to use to filter. If you have changed the name of your control, or have any existing 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
The following are required in order for this to work:
Step 6: Apply the filter to the items on the page
|Select the item that you wish to filter, and choose the filter you have just created in Object Inspector > Inputs > FILTERS & WEIGHT > Filter(s).
The example below applies the Age filter to a bar chart, allowing users to filter data using the combo box. Alter the combo box selection to alter the bar chart.
Step 7: Export your dashboard
|Now go to Export > Web Page. You can now select categories from the combo box and the outputs and the page will automatically update.|
An Alternative Solution to Filtering a Visualization
If you are specifically looking to filter the rows/columns from a table to show in a visualization, you can skip steps 5 and 6 above and use your control box directly in your visualization. From the Object Inspector of your visualization, you can filter the rows by changing Inputs > ROW MANIPULATIONS > Select rows to show by to Choosing from Combo Box or List Box control and selecting the name of your control from the Rows to show drop down. There are corresponding fields to filter columns under Inputs > COLUMN MANIPULATIONS.