In the previous blog in this series, we learnt how to swap, sort and rank R widgets. In this blog, we will see how to leverage slider widgets in SAP Analytics Cloud analytic applications to interact with R visualization.

***

The scenario is to analyse the customers that have the highest debt ratio (here the debt is considered doubtful when the overdue amount is > 120 days). A slider is used to control the minimum doubtful debt, and Range Slider is used to control the percentage of doubtful debt within the total amount due.

sap-analytics-cloud-r-visualization-series-5-leveraging-measure-filters-using-slider-widgets

Slider and Range Slider in action

You can see how the Slider and Range Slider widgets are used as a measure filter for R Visualization in action below.

sap-analytics-cloud-r-visualization-series-5-leveraging-measure-filters-using-slider-widgets

Slider and Range Slider in action

 

Add Slider and Range Slider

Add a slider to the canvas and configure it with minimum, maximum and default values as shown below.

sap-analytics-cloud-r-visualization-series-5-leveraging-measure-filters-using-slider-widgets

Slider configuration in SAP Analytics Cloud

 

Add a range slider and configure it. You can modify the look and feel in the Styling panel.

sap-analytics-cloud-r-visualization-series-5-leveraging-measure-filters-using-slider-widgets

Range Slider configuration in SAP Analytics Cloud

 

Passing input variables to R

Add the following scripts in the OnChange event of Slider and Range Slider widgets to pass the values to R Visualization.

sap-analytics-cloud-r-visualization-series-5-leveraging-measure-filters-using-slider-widgets

Slider OnChange event script

 

sap-analytics-cloud-r-visualization-series-5-leveraging-measure-filters-using-slider-widgets

Range Slider OnChange event script

The getValue() function is used to get the values from the slider. Similarly, getStartValue() and getEndValue() does the same job for range slider component. Debt_value, Precent_debt_min and Precent_debt_max are R input variables, and these are set using the setNumber() API.

Add the following script in the OnInitialization event to initialize the variables to R Widget and avoid errors on application startup.

sap-analytics-cloud-r-visualization-series-5-leveraging-measure-filters-using-slider-widgets

Application OnInitialization script

 

Initializing the Data Frame in R Widget

Add R Visualization widget to the canvas and choose a data source. After which you will be able to add rows and columns from the Input Data panel. You can find a detailed explanation on creating and adding data frames here. Select the fields required, in this case, Company, Customer dimensions and Doubtful Debt, % Doubtful Debt measures.

sap-analytics-cloud-r-visualization-series-5-leveraging-measure-filters-using-slider-widgets

R Data Frame initialized with rows and columns

 

plotly  – Scatter Plot Visualization

This blog uses the plotly library to produce enhanced visuals. You can refer to the blog Adding Interactivity and Customizations to  R widgets for more detailed customizing options in plotly.

The R script in the snapshot below explains how to create a scatter plot chart and modify the axis limits based on the user selection made from Slider widgets.

sap-analytics-cloud-r-visualization-series-5-leveraging-measure-filters-using-slider-widgets

R script to plot a scatter chart in SAP Analytics Cloud

 

Save and run the application. When you make a selection in the sliders, the corresponding values get passed to R Visualization and the R script gets executed visualizing a scatter plot. You can try adding the functionality to multiple charts and filter types as well.

***

Check out our other blogs on R Visualization series here. Reach out to us here today if you are interested in evaluating if SAP Analytics Cloud is right for you.

 

Subscribe to our Newsletter

5920 Windhaven Pkwy
Plano TX 75093.

+1 888-227-2794

+1 972-232-2233

+1 888-227-7192

solutions@visualbi.com