Skip to content
This repository has been archived by the owner on Apr 7, 2022. It is now read-only.

Add govuk_DT() features #63

Open
mattkerlogue opened this issue May 29, 2020 · 5 comments
Open

Add govuk_DT() features #63

mattkerlogue opened this issue May 29, 2020 · 5 comments

Comments

@mattkerlogue
Copy link
Contributor

Have recently experimented with applying gov.uk style guidelines to interactive {DT} tables in {govdown}. This is an issue to discuss development ahead of a future PR.

@mattkerlogue
Copy link
Contributor Author

@mattkerlogue
Copy link
Contributor Author

THOUGHT: There should be a single user facing function govuk_DT() (or some other sensible name).

Should this function:

  1. Render a data.frame passed to it? Or,
  2. Apply styling to a DT::datable() object already defined by the user

(1) gives full control over the rendering and styling of the table, also allows the function to generate filtering controls, likely limits extent of using advanced {DT} functionality (may not be a bad thing). Main thing I'm thinking of here is using the DT::format_*() functions that allow styling (e.g. percentages), and specifiying options such as column visibility/column names. Formatting can be acheived by using {formattable} functions on the source dataset.

(2) gives greater controls over the design and structure of the table, but potential to cause design conflicts/javascript errors if the table includes unexpected elements.

@nacnudus
Copy link
Collaborator

nacnudus commented Jun 4, 2020

Can DT apply formatting in layers?

@mattkerlogue
Copy link
Contributor Author

With {DT} you create a datatables object DT::datatable() which you can then pipe to formatters, which can format the number (e.g. percent, currency) or the style.

Details here, with some very shocking formatting decisions.

From experience you can apply {formattable} to columns in your df e.g.

iris2 <- iris %>% mutate_at(Sepal.Length, formattable::percent, digits = 1)

And then supply this to your DT call, and it'll still show up as a percentage

DT::datatable(iris2)

@nacnudus
Copy link
Collaborator

I think a pipeable formatter would be the best approach.

iris %>%
  mutate(x = scales::percent(x)) %>%
  DT::datatable() %>%
  govdown::govdownify() %>%
  more_formatting() # User takes responsibility for conflicts with govdown from here on

As a rule I'm not in favour of using DT or similar to change the values in a table. I think that should be up to scales::percent and glue and whathaveyou.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants