Introduction
This article describes how to use Controls (eg Combo box) to let the user select which Calculation outputs they wish to show on the Page.
The article contains the steps required to create the below page, where the user can use a Control Box to either show or hide the comment.
Requirements
- A Control Box control (see How to Create a Combo Box Filter or How to Create a List Box Filter).
- A Calculation output to show or hide.
Method
- 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 question labels you wish to appear in the list (eg Show comments; Hide comments). All items in the list should be separated by a semi-colon (;).
- OPTIONAL: Create a Calculation you wish to control with the Control. You can also use an existing output such as a Visualization created in Displayr. The example below is created using Calculation > Custom Code and then adding in the code:
comment = "Wow! This is great! What an insight-filled chart!"
The text is shown in line 1. The rest of the code does the formatting, using HTML.
#Build the HTML for the text
your.html = paste('<style>div.mystyle {font-size: 24px;
font-family: Open Sans; padding-left: 10px;
padding-top: 10px; padding-bottom: 10px; background-color:
#42afe3; color: white ; opacity: 1;}
</style><body><div class = "mystyle">',
comment, '</div></body>', sep="")
# Render the HTML
my.comment = rhtmlMetro::Box(text = your.html, text.as.html = TRUE) - Select the Calculation output you wish to control and go to Home > Appearance > Hide.
- Go to Calculation > Custom Code.
- Click on the Page where you want to position the output.
- Update and input the below R Code:
if (Combo.box == "Hide comments") "" else my.comment
The above code looks up the selected value in our Control box (eg "Hide comments) and if matched returns "" (an empty Calculation output). If the selection in our Control box doesn't match the Calculation returns my.comment (the Calculation created in Step 3).
You will need to update the above code and replace Combo.box with the name of your control. You will also need to replace the mentions of 'Hide comments', and 'Show comments') with the items from your Item list (Step 2). And finally, you will need to replace my.comment with the name of the Calculation Output you wish to control.
To find the name of the Control or the Calculation Output, select it and go to the object inspector > Properties > General > Name.
See Also
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 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 Change Weighting using a Control Box
How to Use a Control Box as an Input for Calculations
Comments
0 comments
Article is closed for comments.