When building dashboards using Displayr, users tend to focus on data tables and various visualizations (for understandable reasons). Bug suppose we want to display key metrics in a top-line bulleted list. How can we achieve this in Displayr? Fortunately, we can do this with some very simple R code.
In this example, I have three key sample profiling metrics that I want to provide in a bullet point list: population, Internet penetration, and household income. In addition, I want to create a dynamic list so that I can filter by specific segments in my data. To do this in Displayr we will:
Requirements
A Displayr Document
The following example was created using the Households.sav data file in a Displayr document.
Please note these steps require a Displayr license.
Method
Creating the source tables
1. Drag the "Population size", "Home internet", and "Household Income" variables from the Data Sources tree onto the Page to create summary tables.
2. With the tables selected, tick the Hidden from exports & publishing checkbox from the General tab of the object inspector.
Now that I have the data tables I need, the next step is to create the bullet-point objects using some R code.
Creating the bullet point objects
- From the toolbar, click Calculation > Custom Code > click on the page to place the custom calculation.
- Paste the following in the R Code editor. You will need to modify table names to match the ones in your data. The Unicode character for a bullet is "U2022".
a <- "\U2022"
# Pull in population
pop <- table.Population.size[1][1]
formatted_pop <- format(round(pop, 0), big.mark = ",")
bullet.1 <- paste(a, formatted_pop, "population")
# Pull in % of households with home internet
internet <- table.Home.internet[2]
bullet.2 <- paste(a, " ", round(internet, 0), "%", " Home internet penetration", sep="")
# Pull in % of households who earn Under $30,000 per year
income <- table.Household.Income[1]
bullet.3 <- paste(a, " ", round(income, 0), "%", " of households make under $30,000 per year", sep="")
my.list <- paste(bullet.1, bullet.2, bullet.3, sep = "\n") - Click Calculate
With a bit of formatting, I get the following bulleted output:
Formatting options are available in the Appearance > Appearance section of the object inspector. You can modify things such as the font style, font size, color, border, etc.
Creating filters
Next, I want to create a filter using a Lifestage segmentation variable in the data set.
- Select the Lifestage variable in the Data Sources tree.
- Hover and click + > Filter > Filters from Selected Data.
Displayr creates a new filter variable set, "Lifestage Filters", in the Data Sources tree. This new variable set is automatically available to be used as a filter. The Usable as a filter checkbox is ticked automatically in the object inespector when the filters are created. You can read more on filtering in Displayr here.
Publishing the page
- Select the Share > Publish to web.
- Under Advanced Options, tick the Hide navigation pane checkbox.
- Click Publish.
- Click Open in new tab.
You can dynamically filter the resulting web page output by the Lifestage filters. The bullet point list will be updated accordingly.