All Projects → cbailiss → basictabler

cbailiss / basictabler

Licence: other
Construct Rich Tables for Output to HTML/Excel

Programming Languages

r
7636 projects

Projects that are alternatives of or similar to basictabler

Lookup
A repository of journalist's lookup tables.
Stars: ✭ 95 (+179.41%)
Mutual labels:  tables
Mui Datatables
Datatables for React using Material-UI - https://www.material-ui-datatables.com
Stars: ✭ 2,246 (+6505.88%)
Mutual labels:  tables
pivottabler
Create Pivot Tables natively in R
Stars: ✭ 108 (+217.65%)
Mutual labels:  htmlwidget
Django Tables2
django-tables2 - An app for creating HTML tables
Stars: ✭ 1,360 (+3900%)
Mutual labels:  tables
Rei
Process lists easily
Stars: ✭ 142 (+317.65%)
Mutual labels:  tables
Table Magic
Converts between CSV, HTML and Markdown. Has a little form editor and a preview.
Stars: ✭ 243 (+614.71%)
Mutual labels:  tables
Kingtable
Library for administrative tables that are able to build themselves, on the basis of the input data.
Stars: ✭ 60 (+76.47%)
Mutual labels:  tables
sortable
R htmlwidget for Sortable.js
Stars: ✭ 109 (+220.59%)
Mutual labels:  htmlwidget
Pdftabextract
A set of tools for extracting tables from PDF files helping to do data mining on (OCR-processed) scanned documents.
Stars: ✭ 1,969 (+5691.18%)
Mutual labels:  tables
bpmn
BPMN diagrams in R
Stars: ✭ 16 (-52.94%)
Mutual labels:  htmlwidget
Laravel Table
Generate tables from Eloquent models.
Stars: ✭ 101 (+197.06%)
Mutual labels:  tables
Tables.jl
An interface for tables in Julia
Stars: ✭ 141 (+314.71%)
Mutual labels:  tables
lineup htmlwidget
HTMLWidget wrapper of LineUp for Visual Analysis of Multi-Attribute Rankings
Stars: ✭ 51 (+50%)
Mutual labels:  htmlwidget
Form
Form is an iOS Swift library for building and styling UIs
Stars: ✭ 99 (+191.18%)
Mutual labels:  tables
vitessceR
R API and htmlwidget for Vitessce
Stars: ✭ 19 (-44.12%)
Mutual labels:  htmlwidget
Expss
expss: Tables and Labels in R
Stars: ✭ 65 (+91.18%)
Mutual labels:  tables
React Super Responsive Table
Turn the tables on unresponsive data!
Stars: ✭ 207 (+508.82%)
Mutual labels:  tables
quickglobe
🌎 View Country Data via a 3D, D3, Globe 🌍
Stars: ✭ 22 (-35.29%)
Mutual labels:  htmlwidget
c3
c3 HTMLWidget Ploting
Stars: ✭ 39 (+14.71%)
Mutual labels:  htmlwidget
taucharts
📊 An R htmlwidget interface to the TauCharts javascript library
Stars: ✭ 66 (+94.12%)
Mutual labels:  htmlwidget

basictabler

R-CMD-check CRAN_Status_Badge

The basictabler package enables rich tables to be created and rendered/exported with just a few lines of R.

The basictabler package:

  • Provides an easy way of creating basic tables, especially from data frames and matrices.
  • Provides flexibility so that the structure/content of the table can be easily built/modified.
  • Provides formatting options to simplify rendering/exporting data.
  • Provides styling options so the tables can be themed/branded as needed.

The tables are rendered as htmlwidgets or plain text. The HTML/text can be exported for use outside of R.

The tables can also be exported to Excel, including the styling/formatting. The formatting/styling is specified once and can then be used when rendering to both HTML and Excel - i.e. it is not necessary to specify the formatting/styling separately for each output format.

Using the flextabler package it is also possible to output tables to Word and PowerPoint.

basictabler is a companion package to the pivottabler package. pivottabler is focussed on generating pivot tables and can aggregate data. basictabler does not aggregate data but offers more control of table structure.

For more information see http://www.basictabler.org.uk/.

Installation

You can install:

  • the latest released version from CRAN with
install.packages("basictabler")
  • the latest development version from github with
devtools::install_github("cbailiss/basictabler", build_vignettes = TRUE)

Examples

Trivial Example

Creating a tiny HTML table from a data frame and immediately rendering it as a htmlwidget:

library(basictabler)
qhtbl(data.frame(a=1:2, b=3:4))

Another Example

Creating a table from a data frame, specifying column names and value formats:

# aggregate the sample data to make a small data frame
library(basictabler)
library(dplyr)
tocsummary <- bhmsummary %>%
  group_by(TOC) %>%
  summarise(OnTimeArrivals=sum(OnTimeArrivals),
            OnTimeDepartures=sum(OnTimeDepartures),
            TotalTrains=sum(TrainCount)) %>%
  ungroup() %>%
  mutate(OnTimeArrivalPercent=OnTimeArrivals/TotalTrains*100,
         OnTimeDeparturePercent=OnTimeDepartures/TotalTrains*100) %>%
  arrange(TOC)

# To specify formatting, a list is created which contains one element for each column in 
# the data frame, i.e. tocsummary contains six columns so the columnFormats list has six elements.
# The values in the first column in the data frame won't be formatted since NULL has been specified.
# The values in the 2nd, 3rd and 4th columns will be formatted using format(value, big.mark=",")
# The values in the 5th and 6th columns will be formatted using sprintf(value, "%.1f")
columnFormats=list(NULL, list(big.mark=","), list(big.mark=","), list(big.mark=","), "%.1f", "%.1f")

# render the table directly as a html widget
qhtbl(tocsummary, firstColumnAsRowHeaders=TRUE,
            explicitColumnHeaders=c("TOC", "On-Time Arrivals", "On-Time Departures",
                                    "Total Trains", "On-Time Arrival %", "On-Time Departure %"),
            columnFormats=columnFormats)

http://cbailiss.me.uk/basictablerreadmeimgs/example1.png

In the example above, the qhtbl() functions returns a html widget that is rendered immediately in the R-Studio viewer window. An alternative is to use the qtbl() function which returns a BasicTable object that can be further manipulated. The styling example further below demonstrates this.

Changing a Table Example

Tables can also be built row-by-row, column-by-column and cell-by-cell. Once built tables can be modified (adding/removing rows columns and cells, merging cells and changing styling). The following example shows more granular ways of building and changing a table:

# data for the table
saleIds <- c(5334, 5336, 5338)
items <- c("Apple", "Orange", "Banana")
quantities <- c(5, 8, 6)
prices <- c(0.34452354, 0.4732543, 1.3443243)

# construct a table column by column
library(basictabler)
tbl <- BasicTable$new()
tbl$cells$setCell(1, 1, cellType="root", rawValue="Sale ID")
tbl$cells$setCell(1, 2, cellType="columnHeader", rawValue="Item")
tbl$cells$setCell(1, 3, cellType="columnHeader", rawValue="Quantity")
tbl$cells$setCell(1, 4, cellType="columnHeader", rawValue="Price")
tbl$cells$setColumn(1, cellTypes="rowHeader", rawValues=saleIds)
tbl$cells$setColumn(2, cellTypes="cell", rawValues=items)
tbl$cells$setColumn(3, cellTypes="cell", rawValues=quantities)
tbl$cells$setColumn(4, cellTypes="cell", rawValues=prices,
                    formats=list("%.2f"))

# example of changing the table - appending a row
formats <- list(NULL, NULL, NULL, "%.2f")
cellTypes=c("rowHeader", "cell", "cell", "cell")
tbl$cells$setRow(5, cellTypes=cellTypes, formats=formats, 
                 rawValues=list(5343, "Pear", 2, 1.0213424))

# example of changing the table - inserting a row
tbl$cells$insertRow(1)
tbl$cells$setRow(1, cellTypes="columnHeader",
                 rawValues=list("Sale ID", "Sale Details", "", ""))

# example of changing the table - merging some cells
tbl$mergeCells(rFrom=1, cFrom=1, rSpan=2, cSpan=1)
tbl$mergeCells(rFrom=1, cFrom=2, rSpan=1, cSpan=3)

# render the final table
tbl$renderTable()

http://cbailiss.me.uk/basictablerreadmeimgs/example4.png

Styling Example

Styling can be specified when creating tables:

# aggregate the sample data to make a small data frame
library(basictabler)
library(dplyr)
tocsummary <- bhmsummary %>%
  group_by(TOC) %>%
  summarise(OnTimeArrivals=sum(OnTimeArrivals),
            OnTimeDepartures=sum(OnTimeDepartures),
            TotalTrains=sum(TrainCount)) %>%
  ungroup() %>%
  mutate(OnTimeArrivalPercent=OnTimeArrivals/TotalTrains*100,
         OnTimeDeparturePercent=OnTimeDepartures/TotalTrains*100) %>%
  arrange(TOC)

# column formats
columnFormats=list(NULL, list(big.mark=","), list(big.mark=","), list(big.mark=","), "%.1f", "%.1f")

# create the table
tbl <- qtbl(tocsummary, firstColumnAsRowHeaders=FALSE,
            explicitColumnHeaders=c("TOC", "On-Time Arrivals", "On-Time Departures",
                                    "Total Trains", "On-Time Arrival %", "On-Time Departure %"),
            columnFormats=columnFormats, 
            tableStyle=list("border-color"="maroon"),
            headingStyle=list("color"="cornsilk", "background-color"="maroon", 
                              "font-style"="italic", "border-color"="maroon"), 
            cellStyle=list("color"="maroon", "background-color"="cornsilk", 
                           "border-color"="maroon"))

# set column alignment of first column
# the arguments are (rFrom, cFrom, rTo, cTo, declarations)
tbl$setStyling(2, 1, 5, 1, declarations=list("text-align"="left"))

# render table
tbl$renderTable()

http://cbailiss.me.uk/basictablerreadmeimgs/example3.png

Excel Output

The same styling/formatting used for the HTML output is also used when outputting to Excel - greatly reducing the amount of script that needs to be written to create Excel output. The only additional formatting that typically needs applying is the Excel cell format strings.

# aggregate the sample data to make a small data frame
library(basictabler)
library(dplyr)
tocsummary <- bhmsummary %>%
  group_by(TOC) %>%
  summarise(OnTimeArrivals=sum(OnTimeArrivals),
            OnTimeDepartures=sum(OnTimeDepartures),
            TotalTrains=sum(TrainCount)) %>%
  ungroup() %>%
  mutate(OnTimeArrivalPercent=OnTimeArrivals/TotalTrains*100,
         OnTimeDeparturePercent=OnTimeDepartures/TotalTrains*100) %>%
  arrange(TOC)

columnFormats=list(NULL, list(big.mark=","), list(big.mark=","), list(big.mark=","), "%.1f", "%.1f")

# create the table
tbl <- qtbl(tocsummary, firstColumnAsRowHeaders=TRUE,
            explicitColumnHeaders=c("TOC", "On-Time Arrivals", "On-Time Departures",
                                    "Total Trains", "On-Time Arrival %", "On-Time Departure %"),
            columnFormats=columnFormats)

# set the styling on the count cells
# the arguments are (rFrom, cFrom, rTo, cTo, declarations)
tbl$setStyling(2, 2, 5, 4, declarations=list("xl-value-format"="#,##0"))
# set the styling on the average delay cells
tbl$setStyling(2, 5, 5, 6, declarations=list("xl-value-format"="##0.0"))

# render the table to an Excel workbook
library(openxlsx)
wb <- createWorkbook(creator = Sys.getenv("USERNAME"))
addWorksheet(wb, "Data")
tbl$writeToExcelWorksheet(wb=wb, wsName="Data", 
                          topRowNumber=2, leftMostColumnNumber=2, applyStyles=TRUE)
saveWorkbook(wb, file="C:\\test.xlsx", overwrite = TRUE)

http://cbailiss.me.uk/basictablerreadmeimgs/example2.png

In the screenshot above, Gridlines have been made invisible to make the styling easier to see (by clearing the checkbox on the 'View' ribbon). Columns were also auto-sized - though the widths of columns could also be manually specified from R. See the Excel Export vignette for more details.

More Information

It is possible to create tables from data frames, matrices, row-by-row, column-by-column and/or cell-by-cell.

Tables can be further manipulated once created, including adding/removing cells/rows/columns and merging cells.

Styling and formatting can be specified for individual cells and ranges of cells.

See the package vignettes for more information:

# to see a list of available package vignettes:
vignette(package="basictabler")
# to open a specific vignette
vignette(topic="v01-introduction", package="basictabler")

The vignettes can also be read on CRAN at: https://cran.r-project.org/package=basictabler

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].