This article describes how to create a Combo Box control and use it as a filter. The article contains the steps to take you from a Page containing a grid of bars chart....
...to a Page containing a Combo Box that can be used to filter the chart.
Requirements
- A Displayr data object to filter (e.g., table, chart, visualization, etc.).
- A Nominal or Binary - Multi variable set to use as a filter (automatic method only).
- A Nominal, Binary-Multi, or Binary-Multi (Compact) variable to use as a filter (manual method only).
Method - Automatic
- Select the output(s) you wish to filter with the Combo Box.
- Go to the Anything menu and select Filter > Control > Combo Box (Drop-Down) Filters on an Output.
- Select the single-response variable(s) you wish to use as a filter.
- Select Yes to allow the user to select more than one category in the Combo Box control, or select No to allow the user to select one category only.
A Combo Box control will appear on the Page. Displayr will create a new Combo Box Filter variable linked to the Combo Box selection. Displayr will also automatically apply the filter variable to all the outputs selected in Step 1.
Method - Manual
Step 1: Create a Combo Box control:
- In the Data Sets tree select the single-response or Binary-Multi variables you wish to use as a filter.
- Create a table by drag and dropping the variable from the Data Sets tree onto the Page.
- Go to the Anything menu and select Page Design > Control > Combo Box (Drop-down).
- Select the Combo Box control, and go to the object inspector > Control > Item list > remove the default text.
- In the Items from the dropdown menu select the table created in step 2 (e.g., Age).
- In the Selection mode dropdown menu select Multiple selection to allow the user to select more than one category in the Combo Box, or select Single selection to allow the user to select one category only.
- OPTIONAL: to change the text appearing in the Combo Box, input the desired text into Placeholder (e.g., Select the age categories to filter).
Step 2: Create the filter and link it to the Combo Box control:
- Go to the Anything menu and select Data > Variables > New > Custom Code > R - Numeric.
- Set the filter Label (e.g., Age filter).
- Paste in one of the following code snippets in R CODE based on the structure of your filter variables.
- Using a Nominal variable to filter: Where Age refers to the name of the variable you wish to use to filter, and Combo.box refers to the label of the Combo Box control.
Age %in% Combo.box
- Using a Binary-Multi or Binary-Multi (Compact) variable set for a multiple-response question: Where Awareness is the variable set used to filter, and Combo.box refers to the label of the Combo Box control. The combo box list items should correspond exactly with the labels of the variables inside the variable set.
rowSums(Awareness[, Combo.box, drop = FALSE]) > 0
- Using a Nominal variable to filter: Where Age refers to the name of the variable you wish to use to filter, and Combo.box refers to the label of the Combo Box control.
Step 3: Apply the filter to desired outputs:
- Select the item that you wish to filter
- Go to object Inspector > Inputs > FILTERS & WEIGHT > Filter(s), and choose the filter.
You can also combine multiple combo boxes into the same filter (step 2), please see How to Combine Multiple R Filter Control Variables into a Single Variable.
Other Considerations
- This filtering is specific to this page and combo box only. Once you get your filtering setup as you like it, you may want to show and apply the same Combo box controls on multiple pages:
- You can apply the filter variable created to outputs on other pages, but those filters will be based off of this specific Combo box on this specific page. This is useful if you want a page of filters that will be used to apply to the whole document.
- To show the same Combo box on multiple pages while keeping the selected items consistent across those pages, see How to Use the Same Control on Multiple Pages for how to do this.
- Keep in mind any item(s) selected in the Combo boxes when you Publish a Document will be the default item selected in View Mode.
Next
How to Use the Same Control on Multiple Pages
How to Create a Combo Box (Drop-Down Control) With a Dynamic List
How to Dynamically Change a Question Based on a Control Box
How to Select Which Rows or Columns to Show in a Visualization Based on a Control Box Selection
How to Switch Logos and Images Based on a Control Box Selection
How to Create a Binary Filter from Selected Data
How to Combine Multiple R Filter Control Variables into a Single Variable
How to Build Tables that Automatically Filter to the Latest Periods
How to Connect Filters to Controls Using R Code
Comments
0 comments
Article is closed for comments.