You can restrict what people see on a Displayr dashboard based on their department, geographic region, or some other user characteristic. For example, you can create a single report to present the results of an employee survey, share it with the managers in your business, and each manager will only see results for their departments.

In Displayr, people's logins can be organized into user groups. These groups are often used to determine which documents a person can view or edit. The user groups are also visible to the code in your document. Thus, you can create a document that responds and changes based on which user groups the viewer belongs to. In this article, I will take you through a simple example of a dashboard that shows different results based on the user's location.

Part 1: Set up User Groups

If the dashboard is to be filtered according to a person's user group, then you need to begin by creating user groups and assigning your users to them.

To create a group:

  1. Log in to Displayr.
  2. Click on the cog icon in the top right and select Settings.
  3. Scroll down to the Groups section and select + New Group.
  4. Enter a Group name
  5. Un-tick Users in this group can explore. (Explore mode allows people to see other data in the data set, so you need to turn this off).
  6. Click Save.

In this article, I am creating a document that will filter results by Australian states, so I have created user groups in my account for each state that my stakeholders come from. The result looks like this:

 

In addition to the default user groups (Administrators, Edit Projects, and View Projects) there is a separate group for each state (ACT, NSW, NT, etc).

Part 2: Assign your users to groups

Next, in order to ensure that people only see results for a subset of the sample, each user requires an individual login and a correctly assigned user group. Importantly, you should avoid assigning these people to any groups that have access to the whole document. It will depend on how you have organized your groups, but typically, restricted users should NOT be part of the default groups like Administrators, Edit Projects, or View Projects.

You can assign a user login to a user group when you first invite them to Displayr. To do so:

  1. Go to your account Settings page.
  2. Click the + New User button in the User section.
  3. Enter the person's Name, Email, and any Notes.
  4. Choose the appropriate group in the Group membership section. You can choose more than one group by holding CTRL and clicking.
  5. Click Save.

In the example above, the user Chris F will be added to the NSW user group when he accepts his invitation to join this Displayr account.

You can also change a person's group membership later on. To do so:

  1. Click the person's name under the Users section.
  2. Fill out the form as above.
  3. Click Save.

Part 3: Create an R Output to identify the user group

Within your document, every page must contain an R Output which accesses the user groups for the person who is currently viewing the page.  One example of the code that you can use is as follows:

  1. Select Insert > R Output.
  2. Enter the code below into the R CODE section.
  3. Click Calculate.
  4. Hide this output by selecting Appearance > Hide.

The code I am using in this example is:

UserGroups = QViewModeUserGroups

if (is.null(UserGroups)) {
    UserGroups = c('NSW', 'VIC')
}
    
if ("Administrators" %in% UserGroups) {
    UserGroups = c('NSW', 'VIC')    
}
    
UserGroupsPage1 = UserGroups

The output will look like this in Edit mode, but will not be visible when viewing the document as it is hidden:

Some notes on how this code works:

  • The special property QViewModeUserGroups is used to obtain the user groups.
  • If you are in Edit mode, then the QViewModeUserGroups property returns a value of NULL. So the second part of the code checks for a NULL value, and in that case, manually assigns user groups NSW and VIC (for New South Wales and Victoria in Australia). When you want to test the appearance in Edit mode, this is the line to change.
  • The third part of the code determines what account administrators will see when viewing the document. Again, here I have assigned NSW and VIC, and this line can be changed when you want to see what a person from a specific user group will see.
  • The final line assigns the name of this output to be UserGroupsPage1. As mentioned above, an output like this needs to be present on every page that you want to filter for the user. It is good housekeeping to name the output according to the page it is used on, particularly when you are making a document with many pages.

Part 4: Create a filter based off of the user groups

For each page you wish to filter by user, you need to construct an R Variable which reads the user groups identified in Part 3, and uses that information to make decisions about which cases should be shown. As I am working with a very simple example, my filter will simply match any respondents whose State variable from the survey matches any of the current user groups.

  1. Select Insert > New R > Numeric Variable.
  2. Enter code like the example below into the R CODE section on the right.
  3. Click Calculate.
  4. Enter a Name and Label for your new variable. Again, as this needs to be done for each page, it is good practice to label your filter according to the name of the page on which it is to be used.
  5. Tick the Usable as a filter box.
  6. Tick the Hidden except in data tree box.
 
State %in% UserGroupsPage1

Some notes about this code:

  • I am using the State variable from my data set. This variable has categories which are the states of Australia (NSW, VIC, SA, etc). For simplicity, I have deliberately chosen my user groups to match the categories of this variable.
  • I have used the %in% operator. This checks each respondent's State category and works out if it is included in the set of user groups for the person currently viewing this page.
  • Depending on the setup of your user groups and how you need to work out which respondents should be included in the sample for each user group you will likely need to use more complicated logic.

Part 5: Filter your page

To make use of your new filter you need to apply it to the outputs on your page.

  1. Holding CTRL on your keyboard, click on all of the tables and visualizations which need to be filtered.
  2. In the Object Inspector, use Inputs > FILTERS AND WEIGHT > Filter(s) to apply this filter variable.

Part 6: Edit the document settings

Now that you have a document ready to go, you need to ensure that all of the user groups have been given permission to view this document.

  1. Click on the button in the very top-left.
  2. Select Document Settings.
  3. Expand the Properties section.
  4. In the Authorised for view only section, select all of the user groups that you created for this document in Part 1 above.
  5. Click Save.

You can't see the whole menu at once, but my selections for this project for step 4 look like this:

Part 7: Publish

Finally, you need to publish your document as a Private Web Page. To do so:

  1. Select Export > Web Page.
  2. Under Who has access, choose Login and password required.
  3. Click Publish.

The link will now be available to copy and share with others, the Open in new tab button will take you to the published version, and the Save button will return you to your document.

Testing

There are two main approaches for testing the function of your dashboard. The first is to use a testing account as follows:

  1. Add a test user (using the steps in Part 3 above) with an email address that is different from the one you use to log in to Displayr. It should be an email account that you have access to so that you can confirm and change the password.
  2. Add the test user to the group that you want to test.
  3. Log out of Displayr and log in again with this test account, or start a Private Browsing or Incognito window in your browser (CTRL + SHIFT + N in Chrome or CTRL + SHIFT + P in Firefox) and log in with the test account.

To test a different group, simply modify the group membership of your test account (as in Part 3 above).

An alternative is to modify the code in Part 3 to determine which group name is provided to Displayr when you view your document from your Administrator account. This will allow you to test different scenarios by modifying the code.