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 highest debt ratio (here the debt is considered doubtful when overdue amount is > 120 days). Slider is used to control the minimum doubtful debt, and Range Slider is used to control the percentage of doubtful debt within total amount due.
You can see how the Slider and Range Slider widgets are used as a measure filter for R Visualization in action below.

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.

Slider configuration in SAP Analytics Cloud
Add a range slider and configure it. You can modify the look and feel in the Styling panel.

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.

Slider OnChange event script

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 start up.

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

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.

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 chart 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
The post SAP Analytics Cloud – R Visualization Series 4 – Leveraging Measure Filters using Slider Widgets appeared first on Visual BI Solutions.