Group Abstract Group Abstract

Message Boards Message Boards

Why a Histogram is not returned properly as image with CloudDeploy?

In Notebook the below code runs properly

myDist[Latitude_, Longitude_] := 
 EstimatedDistribution[
  WeatherData[{Latitude, Longitude}, 
   "MaxWindSpeed", {{1990}, {2015}, "Year"}], 
  GumbelDistribution[\[Alpha], \[Beta]], 
  ParameterEstimator -> "MaximumLikelihood", WorkingPrecision -> 25]

URLExecute[CloudDeploy[api], {"Latitude" -> 40, "Longitude" -> 18}]

and the result is look like this

enter image description here

But I need to deploy to the cloud, and after CloudDeploy and APIFunction used the respond is sometimes only the data set instead of the PNG image with the histogram. Even if I used the same coordinates as input. (i.e 40,18)

enter image description here

POSTED BY: Balazs Kisfali
4 Replies
Posted 8 years ago
POSTED BY: Simon Johnston
POSTED BY: Sean Clarke

Short Answer:

You have to tell APIFunction or whatever you are using to make an Image by specifying what format it should be. Take a look at this code from the documentation:

CloudDeploy[
 APIFunction["country" -> "Country", 
  GeoGraphics[Polygon[#country]] &, "PNG"]]

The last argument to APIFunction is "PNG", telling it to render the output as a PNG.

POSTED BY: Sean Clarke

Hi Sean, Thanks for your answer. Actually I am doing on that way, so the argument is "PNG" Please see the whole code below.

myDist[Latitude_, Longitude_] := 
 EstimatedDistribution[
  WeatherData[{Latitude, Longitude}, 
   "MaxWindSpeed", {{1990}, {2015}, "Year"}], 
  GumbelDistribution[\[Alpha], \[Beta]], 
  ParameterEstimator -> "MaximumLikelihood", WorkingPrecision -> 25]

CloudDeploy[
 APIFunction[{"Latitude" -> "Integer", "Longitude" -> "Integer"}, 
  Show[Histogram[
     WeatherData[{#Latitude, #Longitude}, 
      "MaxWindSpeed", {{1990}, {2015}, "Year"}], 6, 
     "ProbabilityDensity", ChartStyle -> "Aquamarine", 
     PlotRange -> All], 
    Plot[PDF[myDist[{#Latitude, #Longitude}], 
       Quantity[x, "Kilometers"/"Hours"]] // Evaluate, {x, 0, 200}, 
     PlotRange -> {Automatic, All}, 
     PlotStyle -> {Blend[{Blue, Black}], Thick}]] &, "PNG"], 
 Permissions -> "Public"]

However, it doesn't work properly. In some calls is ok but if I call again then the above result can be seen. Can be something with the function itself? What is also strange that in Mathematica notebook has similar output sometimes, after evaluate notebook.

I copy the link here below from the above code. I made it public, so you can test it yourself as well. (at the moment it works with integers) https://www.wolframcloud.com/objects/5cc0a503-f381-4120-af24-89d4282989f9

POSTED BY: Balazs Kisfali
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard