20 Intro
Now we’re going to look at the second part of the Data Visualization part : the tables.
There are several packages in R to create tables. Here, we’re going to focus mainly on 2 :
reactable: https://glin.github.io/reactable/reactablefmtr: https://kcuilla.github.io/reactablefmtr/
The R packages reactable and reactablefmtr are often used together to create highly interactive and visually appealing tables.
The
reactablepackage provides the core functionality for creating interactive HTML tables.The
reactablefmtrpackage is an extension that streamlines the styling and formatting of thesereactabletables with additional features and simpler syntax.
reactablepackage
The package reactable generates interactive tables in R based on the “React Table” JavaScript library. It provides out-of-the-box features that are essential for data exploration and presentation in R Markdown or quarto documents and Shiny applications.
The key features include:
Interactivity: Built-in sorting, filtering, and pagination capabilities.
Customization: Supports column formatting, expandable rows, nested tables, and custom rendering using R or JavaScript.
reactablefmtrpackage
The package reactablefmtr was developed to simplify the often lengthy code required to style reactable tables. It offers a wide range of easy-to-use functions and themes to enhance the appearance and information density of tables.
The key features include:
Conditional Formatting: Easily apply color scales, color tiles, and data bars within cells.
Visual Elements: Embed images from the web (e.g., country flags, product thumbnails) and incorporate interactive sparklines or gauge charts.
Themes: Apply custom, pre-built themes, including bootstrap-inspired options, to match the look of a website or Shiny app.
Output: Save tables as static PNG files or interactive HTML files.
We will go through a few examples related to Supply Chain (sales analysis, projected demand, projected coverages) to practice, step by step and learn how to use those 2 packages.
We will also introduce very briefly a few other ones :
rhandsontable: https://jrowen.github.io/rhandsontable/gt(great table) : https://gt.rstudio.com/
We will use the library htmltools to customize our tables, creating some specific functions.
The htmltools R package, developed by Posit (formerly RStudio), provides a comprehensive set of functions for creating, manipulating, and rendering HTML content directly from R. It is essential for customizing the UI of Shiny apps, generating R Markdown or quarto contents, and building HTML components, allowing users to define HTML tags, CSS styles, and JavaScript dependencies efficiently.
The key features and capabilities include:
HTML Tag Generation: Functions like
tags$div(),tags$p(), orwithTags()allow users to create HTML structures using R syntax instead of raw HTML.HTML Rendering: It provides methods for rendering these tags into HTML strings or files, including the ability to browse them in a viewer.
Dependency Management:
htmltoolshandles HTML dependencies, such as external CSS files or JavaScript libraries, ensuring they are properly included in the output.Structure Manipulation: The
tagQuery()function allows users to query and modify the underlying structure of HTML components.Integration: It is an essential package for other R packages, particularly
htmlwidgets, enabling the creation of interactive web components.