0
$\begingroup$

I have 3 drop down boxes on one of the tabs in my TabView. Two of the drop down boxes results are used in a Select statement to change data fed to the graph and these work perfectly. The other drop down box result is used in a Part statement and when used causes the TabView to refresh and display the default screen. I have tried everything to stop this from happening but I need help!

ImputeMissingPairs[data_, maxpoints_] := 
 Module[{missingpoints, plotdata}, 
  missingpoints = Complement[Range[maxpoints], data[[All, 1]]];
  plotdata = data;
  Sort[Partition[
    Flatten[AppendTo[plotdata, 
      Transpose[{missingpoints, Table[NULL, {Length[missingpoints]}]}]]], 2]]]

vlookup[data1_, data2_, pk1_: 1, col1_: {2}, pk2_: 1] := 
 Module[{look}, look[val_, table_, pk2l_] := Select[table, #[[pk2l]] == val &];
  Join[#, Check[look[#[[pk1]], data2, pk2][[1, col1]], 
       ConstantArray[Null, Length@col1]] // Quiet] & /@ data1]
SelectorName[Name_] := Style[Name, FontFamily -> "Calibri", FontSize -> 11];
SelectorName[List_] := Style[List, FontFamily -> "Calibri", FontSize -> 11];

MonthlyFuel = {{"Year", "Month", "Generator", "SFC", "Base_SFC", "Tar_SFC", 
    "Rated_SFC", "Eff", "Base_Eff", "Tar_Eff", "Rated_Eff", "Base_Eff_%_Var", 
    "Tar_Eff_%_Var", "Rated_Eff_%_Var", "Fuel", "Base_Fuel", "Tar_Fuel", 
    "Rated_Fuel", "Base_Fuel_%_Var", "Tar_Fuel_%_Var", "Rated_Fuel_%_Var", 
    "Base_Fuel_Var", "Tar_Fuel_Var", "Rated_Fuel_Var", "Power", "Energy", 
    "%_Loading", "Running_Time", "Fuel Mix", "Baseline Fuel Mix", 
    "Baseline Null"}, {2012.`, 1.`, "All", 202.3254481`, 217.4737427`, "NULL",
     "NULL", 41.49001792`, 38.6`, "NULL", "NULL", 100.`, 0.`, "NULL", 
    3.180824733`*^6, 3.41897604`*^6, "NULL", "NULL", 6.965574044`, "NULL", 
    "NULL", 238151.3076`, "NULL", "NULL", 4.462483111`, 15721.328`, 
    82.06110907`, 3523.`, "", "", ""}, {2012.`, 1.`, 1, 199.300316`, 
    217.4737427`, "NULL", "NULL", 42.11978505`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 543881.9923`, 593476.4924`, "NULL", "NULL", 8.356607334`, 
    "NULL", "NULL", 49594.50009`, "NULL", "NULL", 4.641083333`, 2728.957`, 
    85.34540885`, 588.`, "", "", ""}, {2012.`, 1.`, 2, 201.5296348`, 
    217.4737427`, "NULL", "NULL", 41.6538564`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 557357.613`, 601453.2118`, "NULL", "NULL", 7.33150941`, 
    "NULL", "NULL", 44095.59882`, "NULL", "NULL", 4.54127422`, 2765.636`, 
    83.51000772`, 609.`, "", "", ""}, {2012.`, 1.`, 3, 202.0456397`, 
    217.4737427`, "NULL", "NULL", 41.5474765`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 566118.5474`, 609347.0737`, "NULL", "NULL", 7.094237122`, 
    "NULL", "NULL", 43228.5263`, "NULL", "NULL", 4.412494488`, 2801.934`, 
    81.1418626`, 635.`, "", "", ""}, {2012.`, 1.`, 4, 199.4107549`, 
    217.4737427`, "NULL", "NULL", 42.096458`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 498827.5987`, 544012.3071`, "NULL", "NULL", 8.305824679`, 
    "NULL", "NULL", 45184.70846`, "NULL", "NULL", 4.451081851`, 2501.508`, 
    81.85144999`, 562.`, "", "", ""}, {2012.`, 1.`, 5, 222.3856501`, 
    217.4737427`, "NULL", "NULL", 37.74742869`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 90746.91076`, 88742.55291`, "NULL", "NULL", -2.2586209`, 
    "NULL", "NULL", -2004.357847`, "NULL", "NULL", 3.849632075`, 408.061`, 
    70.79132173`, 106.`, "", "", ""}, {2012.`, 1.`, 6, 199.8990389`, 
    217.4737427`, "NULL", "NULL", 41.99363095`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 351809.1151`, 382739.4339`, "NULL", "NULL", 8.081299182`, 
    "NULL", "NULL", 30930.31874`, "NULL", "NULL", 4.251048309`, 1759.934`, 
    78.17301047`, 414.`, "", "", ""}, {2012.`, 1.`, 7, 207.6301566`, 
    217.4737427`, "NULL", "NULL", 40.42999632`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 572082.9552`, 599204.9683`, "NULL", "NULL", 4.526333141`, 
    "NULL", "NULL", 27122.01306`, "NULL", "NULL", 4.524298851`, 2755.298`, 
    83.19784573`, 609.`, "", "", ""}, {2012.`, 2.`, "All", 201.8764651`, 
    217.4737427`, "NULL", "NULL", 41.58229371`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 2.877346267`*^6, 3.099654342`*^6, "NULL", "NULL", 
    7.172027919`, "NULL", "NULL", 222308.0748`, "NULL", "NULL", 4.341457508`, 
    14253.005`, 79.83555551`, 3283.`, "", "", ""}, {2012.`, 2.`, 1, 
    199.6444509`, 217.4737427`, "NULL", "NULL", 42.04718154`, 38.6`, "NULL", 
    "NULL", 100.`, 0.`, "NULL", 468983.5816`, 510866.2641`, "NULL", "NULL", 
    8.198365289`, "NULL", "NULL", 41882.68247`, "NULL", "NULL", 4.465958175`, 
    2349.094`, 82.12501241`, 526.`, "", "", ""}, {2012.`, 2.`, 2, 
    202.1588443`, 217.4737427`, "NULL", "NULL", 41.52421082`, 38.6`, "NULL", 
    "NULL", 100.`, 0.`, "NULL", 502980.706`, 541084.8931`, "NULL", "NULL", 
    7.042182766`, "NULL", "NULL", 38104.18709`, "NULL", "NULL", 4.43502139`, 
    2488.047`, 81.55611236`, 561.`, "", "", ""}, {2012.`, 4.`, 3, 
    203.6430766`, 217.4737427`, "NULL", "NULL", 41.22156572`, 38.6`, "NULL", 
    "NULL", 100.`, 0.`, "NULL", 457417.784`, 488483.8665`, "NULL", "NULL", 
    6.359694681`, "NULL", "NULL", 31066.08248`, "NULL", "NULL", 4.319565385`, 
    2246.174`, 79.43297875`, 520.`, "", "", ""}, {2012.`, 2.`, 4, 
    200.2254036`, 217.4737427`, "NULL", "NULL", 41.92518189`, 38.6`, "NULL", 
    "NULL", 100.`, 0.`, "NULL", 426474.103`, 463212.5477`, "NULL", "NULL", 
    7.931228308`, "NULL", "NULL", 36738.44471`, "NULL", "NULL", 4.251437126`, 
    2129.97`, 78.18016046`, 501.`, "", "", ""}, {2012.`, 2.`, 5, 205.5034775`,
     217.4737427`, "NULL", "NULL", 40.84839133`, 38.6`, "NULL", "NULL", 100.`,
     0.`, "NULL", 484094.6778`, 512292.4569`, "NULL", "NULL", 5.504234688`, 
    "NULL", "NULL", 28197.77912`, "NULL", "NULL", 4.244418018`, 2355.652`, 
    78.05108529`, 555.`, "", "", ""}, {2012.`, 2.`, 6, 200.0893227`, 
    217.4737427`, "NULL", "NULL", 41.95369525`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 531605.3161`, 577792.9385`, "NULL", "NULL", 7.993801811`, 
    "NULL", "NULL", 46187.62238`, "NULL", "NULL", 4.327100977`, 2656.84`, 
    79.57155162`, 614.`, "", "", ""}, {2012.`, 2.`, 7, 212.6523627`, 
    217.4737427`, "NULL", "NULL", 39.475162`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 5790.098532`, 5921.375066`, "NULL", "NULL", 2.216994067`, 
    "NULL", "NULL", 131.2765339`, "NULL", "NULL", 4.538`, 27.228`, 
    83.44979772`, 6.`, "", "", ""}, {2012.`, 3.`, "All", 205.0531823`, 
    217.4737427`, "NULL", "NULL", 40.93809407`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 2.741012941`*^6, 2.907042632`*^6, "NULL", "NULL", 
    5.711291951`, "NULL", "NULL", 166029.6919`, "NULL", "NULL", 4.147479677`, 
    13367.327`, 76.26847513`, 3223.`, "", "", ""}, {2012.`, 3.`, 1, 
    200.4231089`, 217.4737427`, "NULL", "NULL", 41.88382523`, 38.6`, "NULL", 
    "NULL", 100.`, 0.`, "NULL", 580495.2711`, 629879.8572`, "NULL", "NULL", 
    7.840318348`, "NULL", "NULL", 49384.58601`, "NULL", "NULL", 4.27190118`, 
    2896.349`, 78.55647628`, 678.`, "", "", ""}, {2012.`, 3.`, 2, 204.121885`,
     217.4737427`, "NULL", "NULL", 41.12487237`, 38.6`, "NULL", "NULL", 100.`,
     0.`, "NULL", 452499.2317`, 482097.7501`, "NULL", "NULL", 6.139526332`, 
    "NULL", "NULL", 29598.51831`, "NULL", "NULL", 4.271308285`, 2216.809`, 
    78.54557347`, 519.`, "", "", ""}, {2012.`, 4.`, 3, 206.0458434`, 
    217.4737427`, "NULL", "NULL", 40.74086781`, 38.6`, "NULL", "NULL", 100.`, 
    0.`, "NULL", 433097.8545`, 457118.716`, "NULL", "NULL", 5.254840956`, 
    "NULL", "NULL", 24020.86151`, "NULL", "NULL", 4.280955193`, 2101.949`, 
    78.72297156`, 491.`, "", "", ""}};

FuelDropDown = {{"Generator", "Measure/Metric", "ChartType", "Comparison", 
    "Year"}, {1.`, "SFC", "RunChart", "Baseline", 2011.`}, {2.`, "FCE", 
    "Variance", "Target", 2012.`}, {3.`, "Fuel", "", "Rated", 2013.`}, {4.`, 
    "Power", "", "", ""}, {5.`, "Energy Produced", "", "", ""}, {6.`, 
    "% Loading", "", "", ""}, {7.`, "Running Hrs", "", "", ""}, {"All", 
    "Fuel Mix", "", "", ""}};

MonthlyFuelHeadings = Part[MonthlyFuel, 1];
DropDownHeadings = Part[FuelDropDown, 1];
GeneratorList = Rationalize[Part[FuelDropDown, 2 ;;, 1]];
MetricList = Part[FuelDropDown, 2 ;;, 2];
YearList = Part[FuelDropDown, 2 ;;, 5];

Part[MonthlyFuel, ;; , 3] = Rationalize[Part[MonthlyFuel, ;; , 3]];
Part[MonthlyFuel, ;; , 3] = 
  Part[MonthlyFuel, ;; , 3] /. n_Integer /; n == 8. -> "All";

(* Initialise variables that will be used later on *)

DropDownYearSelection = 2012.;
FirstGenerator = GeneratorList[[1]];
FirstMetric = MetricList[[1]];
FirstYear = YearList[[2]];
DropDownMetricSelection = MetricList[[1]];
DropDownGeneratorSelection = 1;

(* Create the drop down boxes and their headings *)

DropDownGenerator = Control[{DropDownGeneratorSelection, GeneratorList}];
DropDownMetric = Control[{DropDownMetricSelection, MetricList}];
DropDownYear = Control[{DropDownYearSelection, YearList}];
GenHead = SelectorName["Generator"];
MetricHead = SelectorName["Metric"];
YearHead = SelectorName["Year"];

(* Store the column numbers corresponding to the various drop down options *)

MappingMetricsToColumnsWD = {5, 9, 16, 26, 27, 28, 29, 30};
MappingMetricsToColumnsM = {4, 8, 15, 25, 26, 27, 28, 29};
MetricUnitList = {"g/kWh", "%", "kg", "MW", "MWh", "%", "hrs", "%"};
Tab2Headings = {"Specific Fuel Consumption", "Efficiency", "Fuel Consumption",
    "Power", "Energy Produced", "Percent Loading", "Running Hours", 
   "Fuel Mix"};

(* Convert the user selection to the appropriate column number *)

MetricPosition := 
 Position[MetricList, _?(# == DropDownMetricSelection &)] // Flatten
ColumnInDataM := Part[MappingMetricsToColumnsM, MetricPosition]
ColInDataM := FromDigits[ColumnInDataM]
HeadingTab2 := Part[Part[Tab2Headings, MetricPosition], 1]
ColumnInDataPageHeading := Part[Tab2Headings, MetricPosition]

(* Extract the relevant data sets for plotting *)

MOYGraphData := 
 Select[Part[MonthlyFuel, 
   2 ;;, ;;], #[[3]] == DropDownGeneratorSelection && #[[1]] == 
     DropDownYearSelection &]
MOYGraphData1a := 
 Partition[Riffle[Part[MOYGraphData, ;; , 2], 
   Part[MOYGraphData, ;; , ColInDataM]], 2]


(* Input missing pairs into the data sets *)

MOYGraphData1b := Rationalize[MOYGraphData1a];

(* I now use the function to impute my missing data pairs. *)
MOYGraphData1 := ImputeMissingPairs[MOYGraphData1b, 12];
MOYGraph := Dynamic[ListLinePlot[Tooltip /@ Sort[N[MOYGraphData1]]]]

Tab2 := Column[{Grid[{{YearHead, GenHead, MetricHead}, {DropDownYear, 
       DropDownGenerator, DropDownMetric}}], 
    Column[{HeadingTab2, MOYGraph}, Alignment -> Center]}, Alignment -> Left];

Dashboard := 
 TabView[{"Introduction" -> "IntroPage", "Fuel & Energy" -> Tab2, 
   "Generator Loading" -> "Tab3"}, 1]

(* Displaying the dashboard *)

Dynamic[Dashboard]
$\endgroup$
7
  • 1
    $\begingroup$ You're over cooking it. No need for a dynamic around the tab view as far as I can see -- admittedly after very brief look. Just do this at the end TabView[{"Introduction" -> "IntroPage", "Fuel & Energy" -> Column[{Grid[{{YearHead, GenHead, MetricHead}, {DropDownYear, DropDownGenerator, DropDownMetric}}], Column[{HeadingTab2, MOYGraph}, Alignment -> Center]}, Alignment -> Left], "Generator Loading" -> "Tab3"}, 1] $\endgroup$ Commented Feb 26, 2013 at 10:15
  • $\begingroup$ Yes! Thanks I had no idea this was the problem. I have been sifting throught the full code (much more that what appears above) and was about to give up. Thanks again. $\endgroup$
    – lara
    Commented Feb 26, 2013 at 10:24
  • $\begingroup$ Does either of the following give what you need: (1) use Dashboard instead of Dynamic[Dashboard]? or (2) define Dashboard with Setinstead of SetDelayed: that is, Dashboard= TabView[...]; Dynamic[Dashboard]? $\endgroup$
    – kglr
    Commented Feb 26, 2013 at 10:26
  • $\begingroup$ I realise that using set delayed and dynamic is not necessary and are kind of double-refreshing things. $\endgroup$
    – lara
    Commented Feb 26, 2013 at 10:27
  • $\begingroup$ Lara, exactly:) $\endgroup$
    – kglr
    Commented Feb 26, 2013 at 10:37

1 Answer 1

2
$\begingroup$

Use Dashboard instead of Dynamic[Dashboard] in the last line

and/or

Define Dashboard with Set instead of SetDelayed, that is, change the last two lines to

   Dashboard= TabView[...]; 
   Dynamic[Dashboard] (* or just Dashboard *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.