QScript ReportGroup

From Q
Jump to: navigation, search

ReportGroup

A group in the project's Report tree, or the root of the report tree itself. Obtain the root of the report tree using project.report. Use these to add tables and plots.

appendControl(type)

Creates a new control
typeType of control. The only valid value is "Combobox"
Returns:The new control
Example:
var parent = project.report.appendGroup();
parent.name = "Parent";
var control = parent.appendControl("Combobox");

appendGroup()

Creates a new sub-group. In general you should assign its name immediately after creating it.
Returns:The new ReportGroup object.
Example:
var parent = project.report.appendGroup();
parent.name = "Parent";
var child = parent.appendGroup();
child.name = "Child";

appendImage(image_path)

Creates a new image in the report tree.
image_pathThe path to an image file. This must be a BMP, GIF, EXIG, JPG, PNG or TIFF file. If this is a relative path then it is relative to the running script's directory. If you are running the script on Displayr then this should be the ID returned by /API/Upload after you uploaded a template file.
Returns:The new Image object.
Example:
project.report.appendImage("Q Blue Logo.png");

appendPage(master_slide_name)

Creates a new Displayr page. In general you should assign its name immediately after creating it.
master_slide_nameThe name of the master slide for the new page. Options provided for backwards compatibility are: Item, ItemAndText, TwoItems, TitleOnly, Blank
Example:
var page = project.report.appendPage('Title');

appendPlot(plot_type, questions)

Creates a new plot.
plot_typeA string containing the name of the type of plot you want. e.g. 'Bar/column/line plot'. See the names that appear when you hover your mouse over the plot options in Q.
questionsAn array of Question objects that will be used as the inputs for the new plot.
Returns:The new Plot object.
Example:
project.report.appendPlot("Bar/column/line plot", [project.dataFiles[0].getQuestionByName("Age")]);

appendPlotAutomatic(questions)

Creates a new plot to show the questions passed in. The plot type used is whatever is judged best for the combination of questions passed in. If no plot is able to use the provided questions then a table may be created instead.
questionsAn array of Question objects.
Returns:A Plot object or a Table object.
Example:
var q1 = project.dataFiles[0].getQuestionByName("Q1");
var q2 = project.dataFiles[0].getQuestionByName("Q2");
project.report.appendPlotAutomatic([q1, q2]);

appendR(code)

Creates a new ROutput object in the report tree.
codeR source code.
Returns:The new ROutput object.
Example:
var mat = project.report.appendR("matrix(1:12, 3, 4)");
log(mat.data);

appendTable()

Creates a new table. You must assign questions to the table before it will be useful.
Returns:The new Table object.
Example:
var t = project.report.appendTable();
t.primary = project.dataFiles[0].getQuestionByName("Gender");

appendText()

Creates a new text item in the report tree.
Returns:The new Text object.
Example:
var text = project.report.appendText();
log(text.htmlFragment);

copyAfter(item, after)

Copies a table, plot or sub-group from its current position, to just after after.
itemThe item to be copied.
afterThe child of this group after which it should be added. null will cause it to be copied to the top of its group.
Returns:The new item.

deleteItem()

Deletes a table, plot or sub-group.

equals()

Whether two objects are the same.
Returns:true or false
Example:
data_file.getQuestionByName('Q2').equals(data_file.questions()[0])

exportToExcel(filename, options)

Exports an item or group to Excel. This method is currently only available in desktop Q.
filenameThe name of the exported file.
optionsAn optional dictionary of options to pass to the function. These map to the settings in the Table Options dialog when exporting in Q using the fast Excel export option:
table_style: The name of an Excel-based table style to use for the export. See the dropdown in the Q Excel export dialog for names - remove the spaces when used here.
notes: Text that appears as a comment in the first cell of every sheet.
hyperlink: A link applied if the project is uploaded as a Dashboard.
ignore_net_and_sum: Excludes the NET and SUM columns or rows from the exported table.
export_tables_as: When exporting multiple tables, how they should be laid out:
- OneWorksheetPerTable: each table is placed on a new worksheet.
- OneWorksheetPerGroup: tables in the same group are placed on the same worksheet.
- OneWorksheet: all tables are placed on a single worksheet.
how_count: For multiple tables on the same worksheet, how they should be spaced:
- BetweenTops: use a fixed number of rows between the tops of tables.
- FromBottomOfOneToTopOfNext: leave a number of rows between the bottom of one table and the top of the next.
num_rows_between_tables: The number of rows used by how_count
include_table_of_contents: Whether to include a table of contents
perform_statistical_test_of_independence: Whether to perform a statistical test of independence for the entire table (NB: this is in addition to the tests automatically shown on tables).
repeat_headings: Whether to repeat headings for each table.
show_significance_arrows: Whether to include significance arrows (when shown in table).
table_names_sequential: Whether to name tables sequentially (e.g. Table 1, Table 2, etc.).
show_column_comparisons_in_separate_row: Whether to show column comparisons in a separate row.
Example:
project.report.exportToExcel('output.xlsx');
Example:
project.report.exportToExcel('output.xlsx', {
  table_style: 'TableStyleLight1',
  notes: 'Notes',
  include_table_of_contents: true,
});

group

Get the ReportGroup object that contains this table/plot/group.

guid

Get the internal identifier for this object, which is unique for all objects in the Report.

height

Gets the height of the page in pixels

hiddenFromExportedViews

Gets/sets whether this item is hidden from exported views in Displayr. If an item is hidden from exported views, then when you share or export the project, the item will not appear in the shared page or exported document. This is typically used if you are using R Outputs for intermediate steps in calculating values, and these steps would be irrelevant or confusing for the person viewing the page.
Example:
routput1.hiddenFromExportedViews = true;

moveAfter(item, after)

Moves a table, plot or sub-group from its current position, to just after after.
itemThe item to be moved.
afterThe child of this group after which it should be added. null will cause it to move to the top of its group.

name

Get/set the name for this object, as it appears in the Report.

referenceName

Get/set the reference name for this object, that is used to reference this object in the source code of other objects.

selectedItems()

Returns all normal analysis items (tables, plots, etc., but not their groups) that are selected, or implicitly selected because a parent group is selected.
Returns:An array of tables, plots, etc. (but not groups) in report tree order.
Example:
project.report.selectedItems().forEach(function (item) {
    item.showPercentSign = false;
});

selectedQuestions()

Returns the Question objects that are selected in Q. If the Variables and Questions tab is being viewed, the distinct questions representing the selected rows are returned. On the Data tab, the distinct questions of the selected columns are returned. On the Tables tab, the distinct questions in the dropdowns of the selected items are returned.
Returns:An array of Question objects.

selectedRaw()

Returns all items selected by the user underneath this, including itself. It will not implicitly include any items underneath selected items (for that see selectedItems()).
Returns:An array of items, which may include groups, in report tree order.
Example:
project.report.selectedRaw().forEach(function (item) {
    log(item.name + ' is selected');
});
Example:
// Tests whether a specific item (itemToTest) is selected.
if (project.report.selectedRaw().filter(function (s) {
    return s.equals(itemToTest);
}).length) {
    log(itemToTest.name + ' is selected');
}

selectedVariables()

Returns the Variable objects that are selected in Q. If the Variables and Questions tab is being viewed, the variables representing the selected rows are returned. On the Data tab, the variables of the selected columns are returned. On the Tables tab, the distinct variables of the questions in the dropdowns of the selected items are returned.
Returns:An array of Variable objects.

setSelectedRaw(items)

Set the items to be selected after the script has finished running. Note that this function can only be called from the root of the report tree, i.e., project.report.
itemsAn array of items, which may include groups.
Example:
project.report.setSelectedRaw([project.report.subItems[1]]); // select 2nd item in report tree

subItems

Returns an array of the items under this group. Check their type to find out if they are tables, plots or sub-groups.

type

Returns "ReportGroup".

width

Gets the width of the page in pixels