You can always use the Items From field on a combo box to link the combo box to a variable or output that can update with new options. However, sometimes you may want to set up filtering that has options specific to other filters selected. This could be region-specific to a country selected or product-specific to brands. This article describes how to create a Combo Box drop-down (you can also do this with a List box) where the list of options is dynamic, updating based on the selection in another Combo Box.
In the example below, I've added two combo boxes to the page. The first combo box contains a list of fast food restaurants, and the second combo box is a list of items served at each restaurant. Depending on which restaurant is selected, the list in the second combo box will update accordingly.
Requirements
- A variable containing the values to appear in the first combo box with the higher-level options (e.g., restaurant above).
- A second variable containing the values to appear in the second combo box for the dependent options that correspond to each in the first combo box (e.g., food types above).
- [Optional] If the more granular options are listed multiple times, you will also need a variable in the Data Set to match the larger combo box (i.e., if two brands have a product called the same thing, you will need a variable for product and brand in your Data Set).
- The labels used in the lookup table must exactly match the category labels in the variables.
Method
- Drag the variable that you want to use as the second (dynamically filtered) combo box list onto a page to create a summary table. In this example, I will use the type of food most recently ordered.
- With the table selected, from the object inspector, click Data > Filters & Weight > Combo Box Filters.
- Select the variable that you want to use as the first combo box list. This is the list that will "drive" the second combo box values. In this example, I'll use the list of fast food restaurants.
- Click OK.
- Click Yes if you want users to be able to select more than one option; otherwise, click No.
- A combo box control will appear in the upper left corner of the page. Select it and relocate it on the page, if desired.
- With the summary table selected, go to Data > Rules > + > Rows/Columns > Hide Empty Rows and Columns.
- Right-click the table and select Hide, and drag it off your page.
- From the toolbar, go to Control
> Combo Box (Drop-down).
- Click on the page to place the second combo box control.
- From the object inspector, remove the text in Control > Item list.
- In the Items from dropdown, select the table created at Step 1.
- OPTIONAL: Update Selection mode to Multiple selection if you want to allow more than one selection.
- OPTIONAL: Update When item list changes to Select all if you want the second combo box list to reset.
- See create the filter and link it to the Combo Box control for the instructions to create a custom R variable to link the second combo box to.
- Now you can proceed to create new tables/outputs in your document. Remember to connect both combo box filters to the outputs to see the results.
Next
How to Use the Same Control on Multiple Pages
How to Create a Combo Box Filter
How to Connect Filters to Controls Using R Code
How to Dynamically Change a Question Based on a Control Box
How to Switch Logos and Images Based on a Control Box Selection