Group Abstract Group Abstract

Message Boards Message Boards

Use a function that creates a DateListPlot and works in TabView?

Posted 6 years ago
POSTED BY: Kyle MacLaury
7 Replies
Posted 6 years ago

Rohit and Henrik,

Thank you both! Your advice was quite helpful.

Here is where I ended.

databintoTimeSeries[databin_Databin] := 
 DateListPlot[
  TimeSeries@Map[{#["DATE"], #["KWH"]} &, Normal[Dataset[databin]]]]

TabView[Row[{Rasterize[
       Show[EntityValue[#, "image"], ImageSize -> {40, 40}], 
       Background -> None], #}] -> 
    databintoTimeSeries[EntityValue[#, "monthly bills"]] & /@ 
  EntityList["Campus Building"], ControlPlacement -> Left]

Everything outputs as expected now.

POSTED BY: Kyle MacLaury
Posted 6 years ago

Hi Kyle,

What does this evaluate to?

campusBuldingMonthlyBills[#] & /@ EntityList["Campus Building"]
POSTED BY: Rohit Namjoshi
Posted 6 years ago

Rohit, Thank you, that was a helpful suggestion. I still haven't fully pieced it together, but here is what I've figured out so far. Below I pasted what you suggested before I defined the function, and then after I defined the function. The code did what I expected before I defined the function.

After I define the function some unexpected things happen. The code does seem to be ignoring the Normal[Dataset[ piece of the function, and I'm seeing Entity["Campus Building" repeated in the output, which I don't understand. I think I may need to figure out another way to define my function to work around these issues.

In[5]:= campusBuildingMonthlyBills[#] & /@ 
 EntityList["Campus Building"]

Out[5]= {campusBuildingMonthlyBills[
  Entity["Campus Building", "weld"]], 
 campusBuildingMonthlyBills[Entity["Campus Building", "chapel"]], 
 campusBuildingMonthlyBills[Entity["Campus Building", "barton"]], 
 campusBuildingMonthlyBills[Entity["Campus Building", "bean"]], 
 campusBuildingMonthlyBills[Entity["Campus Building", "bio shelter"]],
  campusBuildingMonthlyBills[Entity["Campus Building", "test"]]}

In[9]:= campusBuildingMonthlyBills[#] & /@ 
 EntityList["Campus Building"]

During evaluation of In[9]:= DateListPlot::ldata: TimeSeries[Entity[Campus Building,weld][{monthly bills[DATE],monthly bills[KWH]}]] is not a valid dataset or list of datasets.

During evaluation of In[9]:= DateListPlot::ldata: TimeSeries[Entity[Campus Building,chapel][{monthly bills[DATE],monthly bills[KWH]}]] is not a valid dataset or list of datasets.

During evaluation of In[9]:= DateListPlot::ldata: TimeSeries[Entity[Campus Building,barton][{monthly bills[DATE],monthly bills[KWH]}]] is not a valid dataset or list of datasets.

During evaluation of In[9]:= General::stop: Further output of DateListPlot::ldata will be suppressed during this calculation.

Out[9]= {DateListPlot[
  TimeSeries[
   Entity["Campus Building", 
     Entity["Campus Building", "weld"]][{"monthly bills"["DATE"], 
     "monthly bills"["KWH"]}]]], 
 DateListPlot[
  TimeSeries[
   Entity["Campus Building", 
     Entity["Campus Building", "chapel"]][{"monthly bills"["DATE"], 
     "monthly bills"["KWH"]}]]], 
 DateListPlot[
  TimeSeries[
   Entity["Campus Building", 
     Entity["Campus Building", "barton"]][{"monthly bills"["DATE"], 
     "monthly bills"["KWH"]}]]], 
 DateListPlot[
  TimeSeries[
   Entity["Campus Building", 
     Entity["Campus Building", "bean"]][{"monthly bills"["DATE"], 
     "monthly bills"["KWH"]}]]], 
 DateListPlot[
  TimeSeries[
   Entity["Campus Building", 
     Entity["Campus Building", "bio shelter"]][{"monthly bills"[
      "DATE"], "monthly bills"["KWH"]}]]], 
 DateListPlot[
  TimeSeries[
   Entity["Campus Building", 
     Entity["Campus Building", "test"]][{"monthly bills"["DATE"], 
     "monthly bills"["KWH"]}]]]}
POSTED BY: Kyle MacLaury

Well, exactly this was the idea in my reply above: Doing it step by step!

  • create a list of images
  • create a list of DateListPlot
  • create the TabView

Then it most likely will become obvious where the problem is. Why is this so difficult?

POSTED BY: Henrik Schachner
Posted 6 years ago

You are passing an Entity to campusBuildingMonthlyBills as the campusbuilding argument, which passes it to EntityValue[Entity["Campus Building", campusbuilding],. That is where the nested Entity calls are coming from. You have coded campusBuildingMonthlyBills to take the name of a building, but you are passing it an Entity.

Follow Henrik's great advice.

POSTED BY: Rohit Namjoshi
Posted 6 years ago

Thank you, Henrik. I played around with your idea a bit, but I’m still struggling. I think it has something to do with TabView. I tried this with another function that also works independently, but doesn’t work within the context of TabView.

POSTED BY: Kyle MacLaury

Kyle,

I cannot really try, because I do not have your data, but maybe when you write your code in a more "step by step" manner, I cannot see why things should not work, e.g.:

ri = ImageResize[#, {40, 40}] &@*ExampleData /@ {{"TestImage", "Girl"}, {"TestImage", 
     "Girl2"}, {"TestImage", "Girl3"}, {"TestImage", 
     "Lena"}, {"TestImage", "Tiffany"}, {"TestImage", "Mandrill"}};
data = Table[{DateObject@RandomInteger[{0, UnixTime[]}], RandomInteger[100]}, {r, 6}, {c, 10}];
dlpl = DateListPlot /@ data;
TabView[MapThread[Rule, {ri, dlpl}]]

enter image description here

BTW: Nice idea to use images as tab labels! Regards -- Henrik

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