1
$\begingroup$

I work with this dataset:

testdata = {
    {DateObject[{2017, 1, 1}, "Day"], 1, 486, 1, 2},
    {DateObject[{2017, 1, 2}, "Day"], 1, 487, 2, 3},
    {DateObject[{2017, 1, 3}, "Day"], 1, 487, 3, 4}, 
    {DateObject[{2017, 1, 4}, "Day"], 1, 486, 4, 5}, 
    {DateObject[{2017, 1, 5}, "Day"], 1, 487, 5, 6}, 
    {DateObject[{2017, 1, 6}, "Day"], 1, 485, 6, 7},
    {DateObject[{2017, 1, 1}, "Day"], 2, 476, 6, 7}, 
    {DateObject[{2017, 1, 2}, "Day"], 2, 487, 5, 6}, 
    {DateObject[{2017, 1, 3}, "Day"], 2, 497, 4, 5},
    {DateObject[{2017, 1, 4}, "Day"], 2, 410, 3, 4}, 
    {DateObject[{2017, 1, 5}, "Day"], 2, 411, 2, 3}, 
    {DateObject[{2017, 1, 6}, "Day"], 2, 412, 1, 2}}

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

I want to create a FormPage with a DataListPlot based on a selection.The next code works fine.

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

enter image description here

When I want to make a selection based on de second column, the code failed.

FormPage[{ "kop" -> {head} -> 1},
 DateListPlot[
   Select[Map[Flatten, testdata, {-4}], #[[2]] == #kop][[All, {1, 
      3}]]] &
 ]

enter image description here

error code: {Message[Part::partw,2,<|kop->2|>],<|kop->2|>[2],<|kop->2|>[2]==2,Select[Map[Flatten,testdata,{-4}],<|kop->2|>[2]==2],Select[Map[Flatten,testdata,{-4}],<|kop->2|>[2]==2][[All,{1,3}]],DateListPlot[Select[Map[Flatten,testdata,{-4}],<|kop->2|>[2]==2][[All,{1,3}]]]}

Who has a suggestion to solve this issue?

$\endgroup$
  • 1
    $\begingroup$ I think the problem is with your Select. In order for that to work it should read Select[...,#[[2]]==value&], but if value is the slot #kop this gets bound to the innermost & and it still doesn't work. This is one of the bad things about using slots, they can't be nested in any simple way, try this: FormPage[{"kop" -> {head} -> 2}, Function[ {x}, DateListPlot[ Select[Map[Flatten, testdata, {-4}], #[[2]] == x &][[All, {1, 3}]]] ][#kop] &]. If I understand what you're tying to do this works. $\endgroup$ – N.J.Evans Sep 27 '17 at 10:28
  • $\begingroup$ Hi N.J. Evans. Your answer is realy good. Maybe you can write it as a answer instead as a comment. $\endgroup$ – Michiel van Mens Sep 27 '17 at 12:07
  • $\begingroup$ Will do, I wasn't sure if that was what you were looking for. $\endgroup$ – N.J.Evans Sep 27 '17 at 12:08

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.