gvisTable: Google Table Chart with R

Description Usage Arguments Value Author(s) References See Also Examples

View source: R/gvisTable.R

Description

The gvisTable function reads a data.frame and creates text output referring to the Google Visualisation API, which can be included into a web page, or as a stand-alone page. The actual chart is rendered by the web browser.

A table that can be sorted and paged. Table cells can be formatted using format strings, or by directly inserting HTML as cell values. Numeric values are right-aligned; boolean values are displayed as check marks. Users can select single rows either with the keyboard or the mouse. Users can sort rows by clicking on column headers. The header row remains fixed as the user scrolls. The table fires a number of events corresponding to user interaction.

Usage

1
gvisTable(data, options = list(), chartid, formats = NULL)

Arguments

data

a data.frame to be displayed as a table

options

list of configuration options for Google Table.

gvis.editor

a character label for an on-page button which opens an in-page dialog box that enables users to edit, change and customise the chart. By default no value is given and therefore no button is displayed.

Further possible components are, taken from https://google-developers.appspot.com/chart/interactive/docs/gallery/table.html#Configuration_Options:

allowHtml

boolean. Default FALSE. If set to TRUE, formatted values of cells that include HTML tags will be rendered as HTML. If set to FALSE, most custom formatters will not work properly.

alternatingRowStyle

boolean. Default TRUE Determines if alternating color style will be assigned to odd and even rows.

cssClassNames

An object in which each property name describes a table element, and the property value is a string, defining a class to assign to that table element. Use this property to assign custom CSS to specific elements of your table. To use this property, assign an object, where the property name specifies the table element, and the property value is a string, specifying a class name to assign to that element. You must then define a CSS style for that class on your page. The following property names are supported:

headerRow - Assigns a class name to the table header row (<tr> element).

tableRow - Assigns a class name to the non-header rows (<tr> elements).

oddTableRow - Assigns a class name to odd table rows (<tr> elements). Note: the alternatingRowStyle option must be set to true.

selectedTableRow - Assigns a class name to the selected table row (<tr> element).

hoverTableRow - Assigns a class name to the hovered table row (<tr> element).

headerCell - Assigns a class name to all cells in the header row (<td> element).

tableCell - Assigns a class name to all non-header table cells (<td> element).

rowNumberCell - Assigns a class name to the cells in the row number column (<td> element). Note: the showRowNumber option must be set to TRUE.

Example: var cssClassNames = {headerRow: 'bigAndBoldClass', hoverTableRow: 'highlightClass'};

firstRowNumber

number. Default 1. The row number for the first row in the data. Used only if showRowNumber is TRUE.

height

string. Sets the height of the visualization's container element. You can use standard HTML units (for example, '100px', '80em', '60'). If no units are specified the number is assumed to be pixels. If not specified, the browser will set the width automatically to fit the table; if set smaller than the size required by the table, will add a vertical scroll bar.

page

string. Default 'disable'. If and how to enable paging through the data. Choose one of the following string values:

'enable' - The table will include page-forward and page-back buttons. Clicking on these buttons will perform the paging operation and change the displayed page. You might want to also set the pageSize option.

'event' - The table will include page-forward and page-back buttons, but clicking them will trigger a 'page' event and will not change the displayed page. This option should be used when the code implements its own page turning logic. See the TableQueryWrapper example for an example of how to handle paging events manually.

'disable' - [Default] Paging is not supported.

pageSize

number. Default 10. The number of rows in each page, when paging is enabled with the page option.

rtlTable

boolean. Default FALSE. Adds basic support for right-to-left languages (such as Arabic or Hebrew) by reversing the column order of the table, so that column zero is the rightmost column, and the last column is the leftmost column. This does not affect the column index in the underlying data, only the order of display. Full bi-directional (BiDi) language display is not supported by the table visualisation even with this option. This option will be ignored if you enable paging (using the page option), or if the table has scroll bars because you have specified height and width options smaller than the required table size.

scrollLeftStartPosition

number. Default 0. Sets the horizontal scrolling position, in pixels, if the table has horizontal scroll bars because you have set the width property. The table will open scrolled that many pixels past the leftmost column.

showRowNumber

boolean. Default FALSE. If set to true, shows the row number as the first column of the table.

sort

string. Default 'enable'. If and how to sort columns when the user clicks a column heading. If sorting is enabled, consider setting the sortAscending and sortColumn properties as well. Choose one of the following string values:

'enable' - [Default] Users can click on column headers to sort by the clicked column. When users click on the column header, the rows will be automatically sorted, and a 'sort' event will be triggered.

'event' - When users click on the column header, a 'sort' event will be triggered, but the rows will not be automatically sorted. This option should be used when the page implements its own sort. See the TableQueryWrapper example for an example of how to handle sorting events manually.

'disable' - Clicking a column header has no effect.

sortAscending

boolean. Default TRUE. The order in which the initial sort column is sorted. True for ascending, false for descending. Ignored if sortColumn is not specified.

sortColumn

number. Default -1. An index of a column in the data table, by which the table is initially sorted. The column will be marked with a small arrow indicating the sort order.

startPage

number. Default 0. The first table page to display. Used only if page is in mode enable/event.

width

string. Sets the width of the visualisation's container element. You can use standard HTML units (for example, '100px', '80em', '60'). If no units are specified the number is assumed to be pixels. If not specified, the browser will set the width automatically to fit the table; if set smaller than the size required by the table, will add a horizontal scroll bar.

chartid

character. If missing (default) a random chart id will be generated based on chart type and tempfile

formats

named list. If NULL (default) no specific format will be used. The named list needs to contain the column names of the data and the specified format. The format string is a subset of the ICU pattern set. For instance, pattern:'#,###%' will result in output values "1,000%", "750%", and "50%" for values 10, 7.5, and 0.5.

Value

gvisTable returns list of class "gvis" and "list".

An object of class "gvis" is a list containing at least the following components:

type

Google visualisation type, here 'Table'

chartid

character id of the chart object. Unique chart ids are required to place several charts on the same page.

html

a list with the building blocks for a page

header

a character string of a html page header: <html>...<body>,

chart

a named character vector of the chart's building blocks:

jsHeader

Opening <script> tag and reference to Google's JavaScript library.

jsData

JavaScript function defining the input data as a JSON object.

jsDrawChart

JavaScript function combing the data with the visualisation API and user options.

jsDisplayChart

JavaScript function calling the handler to display the chart.

jsFooter

End tag </script>.

jsChart

Call of the jsDisplayChart function.

divChart

<div> container to embed the chart into the page.

caption

character string of a standard caption, including data name and chart id.

footer

character string of a html page footer: </body>...</html>, including the used R and googleVis version and link to Google's Terms of Use.

Author(s)

Markus Gesmann markus.gesmann@gmail.com,

Diego de Castillo decastillo@gmail.com

References

Google Table API: https://google-developers.appspot.com/chart/interactive/docs/gallery/table.html

Follow the link for Google's data policy.

See Also

See also print.gvis, plot.gvis for printing and plotting methods.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## Please note that by default the googleVis plot command
## will open a browser window and requires Flash and Internet
## connection to display the visualisation.

## Table with links to wikipedia (flags) 
tbl1 <- gvisTable(Population)
plot(tbl1)

## Table with enabled paging
tbl2 <- gvisTable(Population, options=list(page='enable', height=300))

plot(tbl2)

## Table with formating options
tbl3 <- gvisTable(Population, formats=list(Population="#,###"))

Population[['% of World Population']] <- Population[['% of World Population']]/100 
tbl4 <- gvisTable(Population, formats=list(Population="#,###", 
                                           '% of World Population'='#.#%'))
plot(tbl4)                                           

kleanthisk10/google-motion-charts-with-r documentation built on May 20, 2019, 12:32 p.m.