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

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.
  • Input parameters based on a calculation input control.
  • A script executed to generate the visualization.
    Note
    SAP Analytics Cloud currently supports only SVG and PNG outputs for visualizations.

Procedure

  1. From the Insert menu on the story canvas, select Start of the navigation path(Add)  Next navigation step  R VisualizationEnd of the navigation path.
    An empty R visualization is added to the canvas page.
  2. To configure the input data for the R visualization:
    1. Select +Add Input Data under INPUT DATA.
      The Select Datasource dialog is displayed.
      Note
      If a data source has already been added to the story, it will be used by default.
    2. Choose a model from the Select and Existing Model list and select OK.
    3. 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.
      • 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.
        Note
        To 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.

    4. 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.

  3. To configure an input parameter for your visualization:
    1. 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 Start of the navigation path+Add Input Parameter Next navigation step  +Create a New Calculation Input ControlEnd of the navigation path.
      The Calculation Input Control dialog is displayed.
    2. 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.
    3. 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:
      1. Select a model, select a dimension, and then select Click to Add Values.
      2. 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.

      3. 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.
      4. Select OK.
      For Static List:
    4. Select Click to Add Values and choose either Select by Range or Select by Member.
      1. 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.

      2. Select OK.

      3. 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.

      4. Expand the Settings for Users section, and then choose whether users can do the following in the input control: Single Selection, or Multiple Selection.

      5. Select OK.

  4. 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.
  5. Select the (Expand) icon under Designer to view the Editor, Environment, Console, and Preview panes.
  6. 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 Start of the navigation path(Snippets) Next navigation step ExamplesEnd of the navigation path 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.
  7. 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.