Quantcast
Channel: Visual BI Solutions
Viewing all articles
Browse latest Browse all 989

R Visualizations in SAP Analytics Cloud Series: 1 – Dynamic Filtering

$
0
0

This series is about leveraging R Visualizations in SAP Analytics Cloud. In this blog, let us take a look at creating R widgets in an analytic application and performing dynamic filtering on them.

 

Advantages of R Visualizations in SAP Analytics Cloud

R visualizations are great for creating plots used for exploratory data analysis. R being an open source language, it has countless libraries which allow developers to extensively customize charts starting from UI to the underlying data as per the reporting needs. It is highly flexible and easy to use. For more on R, visit this link.

R visualizations in SAP Analytics Cloud can interact with other SAC components just like any other standard chart. The image below shows a standard column chart in SAC and a column chart created using R.

r-visualizations-sap-analytics-cloud-series-1-dynamic-filtering

 

Dynamic Filtering in R Visualizations

Let us see how to dynamically filter R visualizations. Here, a simple column chart is used. Shown below is the Dynamic filtering of R Visualization in action:

r-visualizations-sap-analytics-cloud-series-1-dynamic-filtering

 

Data-source Acquisition

The input to R visualizations is a Data Frame. A Data Frame is simply like a table with rows and columns where the structure of the table is built based on a list of fields.

Create an R visualization on the canvas. In the Builder tab of the R visualization, input data (data frame) can be added using the Add Input Data option.

r-visualizations-sap-analytics-cloud-series-1-dynamic-filtering

 

For example, add a generic sales data source as input data to the R visualization.

r-visualizations-sap-analytics-cloud-series-1-dynamic-filtering

 

Add the Category dimension to the rows and Volume Sold (Liters) measure to the columns. You can see a preview of the selected rows and columns from the data source on the right side of the input data pane. Click OKto save the structure. Now the Data Frame (Liquor_Sales_Data) is ready to be used for the R visualization.

 

Adding R Script

After the initial Data Frame has been set up, use the Edit Script option from the Builder pane to set up R script to visualize the data.

r-visualizations-sap-analytics-cloud-series-1-dynamic-filtering

 

Add the following script to create a column chart:

r-visualizations-sap-analytics-cloud-series-1-dynamic-filtering

 

The script includes the library ggplot2as it is elegant and easy to use. You can use any library as required. You can learn more about ggplot2 here.

The Data Frame is assigned to a local variable dFrame. The function ggplot renders the column chart with geom_bar(),assigning Category to x-axis and Volume Sold (Liters) to y-axis using the ggplot2::aes()function.

The script pane also displays a preview of the code executed. The developer has the liberty to play around with R scripts here and view the results directly using the Execute command button. When done, click on the Apply button for adding the R visualization to the canvas.

 

Filtering R Visualization

Add a dropdown that would filter dimension Packs from the data model.

1. Configuring the Dropdown

To populate the members, include the following script in the onInitialization() function of the application.

Here the function getMembers() is used to get the list of packs. And the function addItem() is used within a loop to populate the members in the dropdown.

r-visualizations-sap-analytics-cloud-series-1-dynamic-filtering

 

2. Dynamic filtering

Now add the following script in the onSelect() function of the DropDown to achieve dynamic filtering functionality.

Note that you need to get the Data Frame of the R widget using getDataFrame() before you access its data source using getDataSource(), whereas, in the standard SAC chart, the data source can be directly accessed using getDataSource().

Now you will be able to dynamically filter the R visualization.

r-visualizations-sap-analytics-cloud-series-1-dynamic-filtering

 

* * *

In the subsequent blogs, we will learn more about modifying the aesthetic properties of R visualizations in SAP Analytics Cloud.

Reach out to our team here if you are interested in evaluating if SAP Analytics Cloud is right for you.

Subscribe to our Newsletter

The post R Visualizations in SAP Analytics Cloud Series: 1 – Dynamic Filtering appeared first on Visual BI Solutions.


Viewing all articles
Browse latest Browse all 989

Trending Articles