This article includes modified templates for Number visualizations (originally from Visualization > Number and Pictographs) and for all other R-based visualizations, both of which allow users to customize error messages.
Requirements
- A Displayr document.
- You wish to use an R-based visualization. Note, the current Number visualizations are no longer R-based, so this method instead uses the older R-based versions.
Method
Saving the templates to your Displayr Cloud Drive
By saving the templates to your cloud drive, they will then be available to use in any document in your account.
- Download the Number visualization template from here and the other visualization template from here.
- From your account, you can access the cloud drive at the top right of the page via your Initials icon > Displayr Cloud Drive.
- Select the appropriate location and press + Upload.
- Select the downloaded template files and press Upload.
Applying your template to a table
You can apply one of these templates to any table that does not already have the template applied.
- Right-click your table > Apply Template.
- Search for the previously saved template in the appropriate folder and select it.
- Press Apply.
Re-saving your template
If you wish to change the default settings of the template with those that you use most often, you can save it back to the cloud drive.
- Make the changes you want to save as default.
- Right-click your custom formatted table > Save as Template.
- Select the appropriate name and location.
- Press Save.
Added Options
Data > Output
Display / Chart type - This allows you to change Visualization type, as applying the modified template will remove the ability to use the built-in Visualization selector.
Chart > Data Label
Prefix - For the Number visualizations, this now includes a built-in option to conditionally add "+" as a prefix to positive values only when this character is entered here.
Chart > Error Message
At the bottom of the the Chart tab is a new expandable section with the following options:
- Customize error message - Tick this option if you wish to replace the default error message format and/or text.
-
Custom HTML - Optionally select a calculation which stores HTML as text to replace all data-based error messages. You can create this output via the Calculation icon
in the toolbar > Custom Code and clicking on your page. An example of this HTML is below which additionally uses one of the Font Awesome icons.
library(rhtmlMetro)
message <- 'There is an error with this data'
text <- paste('
<div style="color: white; font-size: 16pt; font-weight: bold; text-align: center; padding: 0 12pt">', message, '</div>
')
icon <- '
<div><i class="fas fa-exclamation-circle" style="color: red; font-size: 48pt"></i></div>
'
box_color <- '#61A1E9'
box_html <- paste('
<div style="height:100%;', 'background:', box_color, ';display:flex; flex-direction: column; align-items: center; justify-content: center; gap: 12pt">', text, icon, '</div>
')
fontawesome_css <- '<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">'
err.html <- paste(fontawesome_css, box_html)
When Custom HTML is not used, you can instead use the built-in GUI options:
- Override text - Enter a default message to use for all data-based errors. Otherwise when empty, it will use the built-in messages.
- Font settings - Set font family, color, size and weight of the message text.
- Background color - Set the color of the message background.
Next
How to Handle Outputs With Small or No Data Using R
How to Hide an Output with a Small Sample Size Using an R Error