Output containers are objects that hold a collection of other objects, and displays all its contents, even when they are complex interactive objects and MIME type. By default the contents are just stacked up on the page, but you can configure them to get tabs, grid, cycling, or other layout methods. There is also a class for having no visible output at all: hidden outputs.
In [ ]:
// something we don't want to see
def big(x) {
return (x < 2) ? x : [x, big(x - 1), big(x - 2)]
}
x = big(10)
OutputCell.HIDDEN
In [ ]:
def o = new OutputContainer()
o.addItem("simplest example")
o << [2, 3, 5, 7] // shorter syntax
o << HTML("<h1>title</h1>")
o << null
In [ ]:
def rates = new CSV().read("../../../doc/resources/data/interest-rates.csv")
def c = new Color(120, 120, 120, 100)
plot1 = new Plot(initWidth: 300, initHeight: 400) \
<< new Points(x:rates.y1, y:rates.y30, size: 3, displayName:"y1 vs y30") \
<< new Points(x:rates.m3, y:rates.y5, size: 3, displayName:"m3 vs y5") \
<< new Line(x:rates.m3, y:rates.y5, color: c) \
<< new Line(x:rates.y1, y:rates.y30, color: c)
plot2 = new SimpleTimePlot(rates, ["m3", "y1"], showLegend:false, initWidth: 300, initHeight: 400)
plot3 = new SimpleTimePlot(rates, ["y5", "y10"], showLegend:false, initWidth: 300, initHeight: 400)
table = rates[0]
TableDisplay t = new TableDisplay(table);
def l = new TabbedOutputContainerLayoutManager()
l.setBorderDisplayed(false)
def o = new OutputContainer()
o.setLayoutManager(l)
o.addItem(plot1, "Scatter with History")
o.addItem(plot2, "Short Term")
o.addItem(plot3, "Long Term")
o.addItem(t, "1990/01")
o
In [ ]:
plot1.setShowLegend(false)
bars = new CategoryPlot(initWidth: 300, initHeight: 400) << new CategoryBars(value: [[1.1, 2.4, 3.8], [1, 3, 5]])
def lg = new GridOutputContainerLayoutManager(3)
def og = new OutputContainer()
og.setLayoutManager(lg)
og.addItem(plot1, "Scatter with History")
og.addItem(plot2, "Short Term")
og.addItem(plot3, "Long Term1")
og.addItem(plot3, "Long Term2")
og.addItem(table, "1990/01")
og.addItem(bars, "Bar Chart")
og
In [ ]:
l = new CyclingOutputContainerLayoutManager()
l.setPeriod(2000); // milliseconds
l.setBorderDisplayed(false);
def o = new OutputContainer()
o.setLayoutManager(l)
o.addItem(plot1, "Scatter with History")
o.addItem(plot2, "Short Term")
o.addItem(table, "1990/01")
o.addItem(plot3, "Long Term")
o
In [ ]: