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

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

Some things you probably want to know.

Plotting functions do not actually return images. They output some code. This code is then interpreted by the front end as a graphic that you can see. That is, it returns a kind of vector graphic, like SVG which more people are familiar with.

You can see what the underlying code for a graphic looks like by wrapping it in the function "InputForm".

POSTED BY: Sean Clarke
POSTED BY: Balazs Kisfali
Posted 7 years ago

I am seeing a similar problem, I deployed a FormPage and the response seems always to be code. I don't know how to apply the "PNG" trick from above to a FormPage though.

FormPage[
 {{"zips", "Zip Codes"} -> 
   Restricted[
     DelimitedSequence[
      Restricted["String", RegularExpression["\\d\\d\\d\\d?\\d?"]], 
      ","], {2, 1000}] -> 
    StringRiffle[
     Map[(#["Name"]) &, GeoEntities[$GeoLocation, "ZIPCode"]], ","], 
  {"property", "Report"} -> Restricted["String", 
    {{"AverageHouseValue", "MedianHouseholdIncome", 
      "PersonsPerHousehold", "PopulationDensity"}}]}, 
 (GeoRegionValuePlot[
    Module[{p = #property}, 
     Map[(Module[{z = ZIPCodeData[#]}, z -> z[p]]) &, #zips]],
    PlotLabel -> #property, 
    MissingStyle -> Directive[Green, EdgeForm[Dashed]],
    GeoLabels -> (Tooltip[#1, #2] &)]) &, 
 AppearanceRules -> <|"Title" -> "ZIP Code Demographics v2", 
   "Description" -> 
    "Enter two or more comma-separated Zip Codes to compare \
demographic data."|>]

The output from the page starts

Legended[GeoGraphics[Graphics[{{Annotation[{Texture[Image[RawArray["UnsignedInteger8", {{{158, 158, 158, 
POSTED BY: Simon Johnston
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract