Add R Visualizations to Stories
You can insert an R visualization into a story by running R scripts on an externally
deployed R environment, or an R server runtime environment deployed by SAP Analytics Cloud if it available in
your region.
Prerequisites
To fully utilize the interactive HTML capabilities of your R visualizations:
- You need to create a local HTML file in the connected R environment and call
browseURL with a reference to the local file
path.
- Alternatively, you can use HTML rendering packages that leverage
browseURL with the local HTML file reference.
- Only the first level of HTML dependencies are retrieved and available to render the R
visualization.
Context
An R visualization is based on the following components:
- Input data based on a model, specified dimensions, dimension attributes, and
filters.
Note
Both new models types and classic account models are
supported. For more information on the new model types and classic account
models, see
Get Started with the New Model Type.
- Input parameters based on a calculation input control.
- A script executed to generate the visualization.
Note
Dynamic time range filters are not supported for R visualizations.
Procedure
-
From the Insert menu on the story canvas, select
.
An empty R visualization is added to the canvas page.
-
To configure the input data for the R visualization:
-
In the Builder panel, from the Input Data
section, select +Add Input Data.
The
Select Dataset or Model
dialog is displayed.
Note
If a
data source has already been added to the story, it will be used
by default.
-
Choose a model from the list.
-
Use the Table Structure settings to specify the table structure
for your input data.
Note
Select the
(Expand) icon under
Designer to view a
Preview for the input data table
structure.
-
When you have finished setting up the table structure, select OK.
Note
Your input data can be directly referenced as a data frame in the R script editor.
Remember the name used for the input data or, alternatively,
click the displayed entry to specify a new name.
-
To configure an input parameter for your visualization:
-
Under INPUT PARAMETERS, select an input control from the following
options:
- If the story already contains calculation input controls, select
+Add Input Parameter and choose any
of the listed parameters.
- To create a new calculation input control, select .
The Calculation Input Control dialog is displayed.
-
Provide a name for the input parameter.
Note
Your input parameters can be directly referenced in the R script
editor. Remember the name used for the parameter or, alternatively,
click the current name to specify a new name.
-
Select Existing Dimension to allow users to pick
from members of a dimension, or Static List to
add custom values as options for the input control.
For
Existing Dimension:
- Select a model, select a dimension, and then select
Click to Add Values.
- Select values from the list of available members.
If you
select Exclude selected members,
all members except the ones selected will be included in
the input control. You can use
(Search) to find specific
values. When you expand the list beside the search icon,
you can choose to view the member
Description, ID
and Description, or
ID.
- Expand the Settings for Users
section, and then choose whether users can do the following
in the input control: Single
Selection, Multiple
Selection, or Multiple Selection
Hierarchy.
- Select OK.
For Static List:
-
Select Click to Add Values and choose either Select by
Range or Select by Member.
-
If you have selected Select by
Range, enter the
Min and
Max values for your range in
the Set Values for Custom Range
dialog. You can optionally set an
Increment value.
-
Select OK.
-
To create a member based input control, add numeric
values to the Custom Members area
in the Select Values from Custom
LOV dialog, and then select
Update Selected Members.
-
Expand the Settings for Users
section, and then choose whether users can do the
following in the input control: Single
Selection, or Multiple
Selection.
-
Select OK.
-
Under Script, select + Add Script to create a
new script, or Edit Script if a script has previously
been specified.
The Script panel is displayed over the
Designer.
-
Select the
(Expand) icon under Designer to
view the Editor, Environment,
Console, and Preview
panes.
-
Enter your script in the Editor and select
Execute.
Note
- A list of suggested code is displayed if you press
Ctrl
+ +
+ Space
, or if there are multiple suggestions based on the
characters you have typed in the Editor.
Based on your coding context, the available R functions, data
frames, R packages, vectors, arguments, input parameters, and
function lists appear on the left with a corresponding description
(if available) on the right.
To reference a data frame, enter the three letters of the data frame name. All data frame
and input data names are preceded by the icon. All input
parameter names are preceded by the icon.
- You can use the up, down, PgUp
PgDn, Home, and End keys to
navigate the displayed list of suggestions. Select a suggestion to
insert it into your script.
- If you combine a data frame name with $, a list of the
column names for the data frame is displayed.
If the script is processed successfully, the following is
displayed:
- The variables from the script output are listed in
Environment.
- The outputted code from the executed script is displayed in
Console.
- Any visualization rendered by the executed script is displayed in
Preview.
Note
Sample scripts to render R based visualizations are provided for your convenience. Go to
to access the samples. The code and visualizations rendered
by these samples are for instructional purposes. If you have the requisite R
programming background, you can use these samples to generate visualizations
based on your data.
-
Select Apply to insert the R visualization into the current canvas
page.
Note
You cannot export interactive HTML content to PDF. You cannot use
remote or key figure models as input data. All hierarchies in models are
flattened when working with R.