1. Dashboard Tables
We've talked about two types of visual displays: graphs, and components that highlight single values. Now we'll move on to something that might not have as obvious a place on a dashboard: tables. While dashboards are focused on visuals, tables can play an important role in making sure viewers have critical details about the underlying data.
2. Basic tables
The simplest way to add a table to your dashboard is with the kable function, which is in the knitr package. Just pass your dataframe to the kable function, and you'll have a table! However, much like using static graphs in your dashboard, these tables don't feel very web-friendly. If they take up more space than the chart is allotted, the user will need to scroll down to see the rest of the table. And, they aren't interactive, which makes it harder for them to be useful unless the table is very small.
3. Web-friendly tables
As with graphs, there is a web-friendly alternative for making tables: another htmlwidget package called DT. The important function here is datatable. Just like with kable, simply pass your dataframe to the datatable function, and you'll have a web-friendly table. Without any extra work, you get a table that is searchable, sortable, and paginated.
4. Eliminating row numbering
The datatable function has many possibilities for formatting and additional features. One thing you may often want to change is to eliminate the column of row numbers that is added by default, using the rownames argument.
5. Changing rows per page
Many customizations available with datatable are accomplished with the options argument, which takes a list. One example of this is changing the number of rows that are shown on each page by default, by setting the pageLength in the options list. Note how this is different than how we set the rownames parameter, which is not part of the options list.
6. Adding buttons
Datatable provides features beyond just simple customizations. This example uses the Buttons extension. It will produce the same table as before, but now with buttons across the top that allow your dashboard viewers to extract the data from the table by a method of their choosing. Note that this requires both the extentions argument _and_ some elements on the options list.
7. More information on DT
There are a lot more ways to customize your tables with the DT package. Information and examples can be found on this website.
8. Let's practice!
Now it's your turn.