Call Web Service to Extract Images

October 22, 2016

Report Abuse
This experiment shows how to plot using ggplot2, and how to call this in RRS mode and extract images from the output base-64 encoded strings
This experiment has an Execute R Script module that creates 4 plots using ggplot2 library. You can see the plots by visualizing the 2nd output port of the Execute R Script module. After deploying a web service out of this predictive experiment, you can then use the following PowerShell scripts to call the RRS endpoint and save the images as 4 png files locally. Import-Module AzureMLPS.dll $url = '**RRS Endpoint URL**' $key = '**API Key**' $saveToDir = 'c:\temp\' # This web service has no input $input = '{}' # output in JSON format $output = Invoke-AmlWebServiceRRSEndpoint -ApiLocation $url -ApiKey $key -InputJsonText $input # convert to JSON object $x1 = ConvertFrom-Json -InputObject $output # get the inner JSON string from "output1" $x2 = $x1.Results.output1.value.Values[0][0] # convert to JSON object $x3 = ConvertFrom-Json -InputObject $x2 # get the actual outputs: 0 is StdOut, 1 is StdErr, and 2 is Graphics Device $x4 = $x3.sections[2].values # save all plots to "c:\temp\n.png" where n = 1 to 4. for ($i = 0; $i -lt $x4.Length; $i++) { [io.file]::WriteAllBytes($saveToDir + $i.ToString() + '.png', [System.Convert]::FromBase64String($x4[$i].data)) } To get the Azure ML Studio PowerShell Module, visit [http://aka.ms/amlps](http://aka.ms/amlps). You can also do this in C#/Python/R etc.