0
$\begingroup$

I work with the following dataset:

testdata = {{DateObject[{2017, 1, 1}, "Day"], 486, 1, 
   2}, {DateObject[{2017, 1, 2}, "Day"], 487, 2, 
   3}, {DateObject[{2017, 1, 3}, "Day"], 487, 3, 
   4}, {DateObject[{2017, 1, 4}, "Day"], 486, 4, 
   5}, {DateObject[{2017, 1, 5}, "Day"], 487, 5, 
   6}, {DateObject[{2017, 1, 6}, "Day"], 4851, 6, 7}};

I want to make a interactive graph in the cloud. To make the graph interactive I create the next 'choose-option':

head = {"nr1" -> 2, "nr2" -> 3, "nr3" -> 4};

The next CloudDeploy works fine:

CloudDeploy[FormPage[{ "kop" -> {head} -> 2},
  DateListPlot[
    TimeSeries[Map[Flatten, testdata, {-4}][[All, {1, #kop}]]]
    , PlotStyle -> {Red, Thick}
    , PlotTheme -> {"Scientific", "Wide", "Sans"}
    ] &
  ], Permissions -> "Public"]

enter image description here

Now I want to make some improvements, for example to plot also the 'max', the 'mean', etc.

max=MovingMap[Max,testdata,10]; mean=MovingMap[Mean,testdata,{9,Center},None]; stddev=MovingMap[StandardDeviation,testdata,{9,Center},None];

My first attempt:

CloudDeploy[FormPage[{ "kop" -> {head} -> 2},
  testdata1 = 
   TimeSeries[Map[Flatten, testdata, {-4}][[All, {1, #kop}]]] &;
  DateListPlot[testdata1,
   , PlotStyle -> {Red, Thick}
   , PlotTheme -> {"Scientific", "Wide", "Sans"}
   ]
  ], Permissions -> "Public"]

this is going wrong. I get two messages:

The expression {1,#kop} cannot be used as a part specification. TimeSeries[Map[Flatten,testdata,{-4}][[All,{1,#kop}]]]& is not a valid dataset or list of datasets.

What is the sollution for this problem?

$\endgroup$
  • 1
    $\begingroup$ The second argument to FormPage should be a function. You have (timeSeriesFunction_; plot_) but it should be (timeSeriesFunctionBody_; plot_ )& $\endgroup$ – Kuba Sep 6 '17 at 7:37
  • $\begingroup$ Thanks, Something goes wrong when I ad PlotLegend. Do you understand why? CloudDeploy[FormPage[{ "kop" -> {head} -> 2}, (testdata1 = TimeSeries[Map[Flatten, testdata, {-4}][[All, {1, #kop}]]]; mean = MovingMap[Mean, testdata1, {2, Center}, None]; DateListPlot[{testdata1, mean} , PlotStyle -> {Red, Thick} , PlotTheme -> {"Scientific", "Wide", "Sans"} , PlotLegends -> {"testdata1", "mean"} ]) & ], Permissions -> "Public"] $\endgroup$ – Michiel van Mens Sep 6 '17 at 10:04
  • 1
    $\begingroup$ Plots with legends don't have Graphics head but Legended :-/ and Legended has different export for I guess, you can force it to be e.g. svg: ExportForm[Module[{testdata1, mean}, testdata1 = TimeSeries[Map[Flatten, testdata, {-4}][[All, {1, #kop}]]]; mean = MovingMap[Mean, testdata1, {2, Center}, None]; DateListPlot[{testdata1, mean}, PlotStyle -> {Red, Thick}, PlotTheme -> {"Scientific", "Wide", "Sans"}, PlotLegends -> {"testdata1", "mean"}] ] , "SVG" ] $\endgroup$ – Kuba Sep 6 '17 at 10:20
  • $\begingroup$ Hi Kuba, Can you wrote a shore note how you combine 'ExportForm' with 'FormPage'. I thought : CloudDeploy [FormPage[{"kop" -> {head} -> 2}, ExportForm[ Module[{testdata, mean}, testdata = TimeSeries[Map[Flatten, testdata, {-4}][[All, {1, #kop}]]]; mean = MovingMap[Mean, testdata, {2, Center}, None]; DateListPlot[{testdata, mean}, PlotStyle -> {Red, Thick}, PlotTheme -> {"Scientific", "Wide", "Sans"}, PlotLegends -> {"testdata1", "mean"}]] &, "SVG" ]]], but this is not working. $\endgroup$ – Michiel van Mens Oct 3 '17 at 7:43
  • 1
    $\begingroup$ You need to move & outside ExportForm the second argument is supposed to be a function $\endgroup$ – Kuba Oct 3 '17 at 9:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.