Adding 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
- 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.
- Input parameters based on a calculation input control.
- A script executed to generate the visualization.
Procedure
-
From the Insert menu on the story canvas, select
(Add) R
Visualization.
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.NoteIf 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.
NoteSelect the (Expand) icon under Designer to view a Preview for the input data table structure.
- ROWS: select +Add Dimensions to add
dimensions from the list of available options into your input
data. Hover over a dimension to display the
(More) icon if you want to specify
display options or attributes. Use the
Manage Filters icon to specify filters
for the dimension. NoteTo create a dynamic input control for a given dimension, select the Manage Filters icon and enable the Allow viewers to modify selections option.
-
COLUMNS: is used to manage the available measures. Select All Members to display the currently available measures. Hover over a column entry to display the (More) icon if you want to specify display options or attributes. Use the Manage Filters icon to specify filters for the measures.
-
FILTERS: is used to manage the filters for the input data. Select +Add Filters to specify filters. Use Advanced Filtering to create filters based on multiple dimensions by defining a set of logical conditions. For more information, see Advanced Filtering.
- ROWS: select +Add Dimensions to add
dimensions from the list of available options into your input
data. Hover over a dimension to display the
(More) icon if you want to specify
display options or attributes. Use the
Manage Filters icon to specify filters
for the dimension.
-
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.
-
In the Builder panel, from the Input Data
section, select +Add Input Data.
-
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 +Add Input Parameter +Create a New Calculation Input Control.
The Calculation Input Control dialog is displayed. -
Provide a name for the input parameter.
NoteYour 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 INPUT PARAMETERS, select an input control from the following
options:
-
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.
If the script is processed successfully, the following is displayed: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.
- 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.
NoteSample scripts to render R based visualizations are provided for your convenience. Go to (Snippets) Examples 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.
NoteYou 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.