This article describes how to change images (e.g., brand logos) shown on a Page based on a Combo Box selection. The post contains the steps required to create a Page like this:
- A Control Box (see How to Create a Combo Box Filter or How to Create a List Box Filter).
- A Conditional Image Visualization that changes based on the Control Box selection.
- The URLs of the images you wish to display.
- Go to the Anything menu, and select Page Design > Control > Combo Box (Drop-Down) or List Box.
- With the control selected, go to the object inspector > Control > Item List and input the labels (e.g., brand names) you wish to appear in the list. All items in the list should be separated by a semi-colon (;).
- Still, in the object inspector, go to the Properties tab > General > Name and input the desired name (e.g. brand.switch) to use later in the R code.
- In the toolbar select Calculation > Custom Code.
- Update and input the below R code format:
List = c("Item_List_1", "Item_List_2")The first line of the code lists the items in the same order as defined in Step 2. The second line of the code looks up the position of the selected brand in the list. In our example the code would look like this:
current.selection = match(Control_name, List)
brands = c("Displayr", "Q")To check the code, change the menu selection, and you should see the number in the output update.
current.brand = match(brand.switch, brands)
- Select Visualization > Number > Conditional Image.
- Change Inputs > DATA SOURCE > Data source to Use an Existing R Output.
- Click into Inputs > DATA SOURCE > Input data and select the R Output that you created in Step 5 (in this example it is called current.brand).
- Change Inputs > OUTPUT > Image type to Custom Images.
- Paste the URL of the image associated with Item_List_1 into the Default image field.
- Change Threshold 1 to the number 2.
- Paste the URL for the second brand logo into Image 1.
- Repeat Steps 11 and 12 for each additional image, increasing the threshold by one each time.