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.
You can see how the Slider and Range Slider widgets are used as a measure filter for R Visualization in action below.
Add Slider and Range Slider
Add a slider to the canvas and configure it with minimum, maximum and default values as shown below.
Add a range slider and configure it. You can modify the look and feel in the Styling panel.
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.
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.
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.
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.
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.