Construct Rich Tables for Output to 'HTML'/'Excel'

Easily create tables from data frames/matrices. Create/manipulate tables row-by-row, column-by-column or cell-by-cell. Use common formatting/styling to output rich tables as 'HTML', 'HTML widgets' or to 'Excel'.


Build Status 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.

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.

You can install:

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


Trivial Example

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

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
tocsummary <- bhmsummary %>%
  group_by(TOC) %>%
            TotalTrains=sum(TrainCount)) %>%
  ungroup() %>%
         OnTimeDeparturePercent=OnTimeDepartures/TotalTrains*100) %>%
# 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 %"),

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

It is also possible to create tables row-by-row, column-by-column and/or cell-by-cell.

More Information

See the package vignettes for more information:

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

The vignettes can also be read on CRAN at:


basictabler 0.1.0

Initial version.

Earlier versions

No versions prior to 0.1.0 were released.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


0.1.1 by Christopher Bailiss, 15 days ago

Report a bug at

Browse source code at

Authors: Christopher Bailiss [aut, cre]

Documentation:   PDF Manual  

GPL-3 license

Imports R6, dplyr, jsonlite, htmltools, htmlwidgets

Suggests lubridate, listviewer, openxlsx, shiny, knitr, rmarkdown, testthat

See at CRAN