When viewing a published document in View mode and applying a filter to the Page, the expected behavior is for all outputs on that Page to filter. This is not always the case with Calculations using R Code. This post describes the steps required to ensure Calculations using R Code are also filtered. The posts also contain steps to take if you wish to exclude the Calculations from filtering in View mode.
Requirements
- A Calculation using R Code.
- A binary variable that can be used as a filter.
- A published Displayr document.
Please note these steps require a Displayr license.
Method - Adding a Filter an R Output
- In Edit mode, select the Calculation using R code you wish to filter in View mode.
- In the object inspector > General > R Code add "[QFilter]" to the part of the code referencing the data source (e.g. variable or table).
- Select Calculate.
- Go to Share > Publish as Web Pages > Publish (or Republish).
Method - Removing the Filter from Automatically Created R Output
Many analyses created in Displayr are based on R calculations, with the R code already referencing the "[QFilter]". To remove it follow the steps outlined below.
- Select the automatically created Calculation using R code and go to the object inspector > General > R CODE.
- In the R CODE find all mentions of QFilter and replace them with TRUE.
- Select Calculate.
- Go to Share > Publish as Web Pages > Publish (or Republish).
Method - Uncheck 'Automatic' Calculate
Another approach to ensure that the Calculation using R code doesn't change based on the selected filter in view mode is to disable the Automatic Calculate feature. By doing this the Calculation will remain static in View mode.
- Select the automatically created Calculation using R code and go to the object inspector.
- Untick the Automatic box on the right side of the Calculate button.
- Go to Share > Publish as Web Pages > Publish (or Republish).
See Also
How to Customize the Filter Control List in View Mode
How to Create a Binary Filter from Selected Data