Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Html output in the R viewer (i.e. Better integration with the gt package) #667

Open
michaelquinn32 opened this issue Jul 21, 2021 · 6 comments

Comments

@michaelquinn32
Copy link
Collaborator

The gtsummary package shows some great ideas for producing nice tables with gt.
http://www.danieldsjoberg.com/gtsummary/

It seems like skimr should also be able to support gt methods that produce nice html tables. This should be similar to our support of other approaches for doc-ready tables.

@elinw
Copy link
Collaborator

elinw commented Oct 4, 2021

YEs totally agree with this. gt is really a nice model.

@michaelquinn32
Copy link
Collaborator Author

We're pretty close already with this sort of code snippet:

skim(iris) %>%
  partition() %>%
  purrr::map(gt::gt) %>%
  htmltools::tagList() %>%
  htmltools::browsable()

Four wants:

  1. Make that output above nicer, incorporating the skim summary, titles for each type and appropriate spacing
  2. Decide if an appropriate "viewer" is available to use (likely from getOption("viewer")) for html output
  3. Dispatch appropriate histogram function based on viewer availability. KableExtra can create nice html-friendly sparkgraphs: https://cran.r-project.org/web/packages/kableExtra/vignettes/awesome_table_in_html.html#Insert_Images_into_Columns
  4. Make this the default output when html formatting is available in a notebook: https://colab.research.google.com/drive/1KgT0LGBB7r_qZ3nR5hPWTq8nvSAwzs6P?usp=sharing

@michaelquinn32
Copy link
Collaborator Author

More iteration on this idea, but I think I've got it now.

I think this is really getting us towards skimr 3.0 territory. It's really exciting.

We need to create a new option: whether or not someone want to use rich html output (and make sure this aligns with jupyter.rich_display). I looked a bit more, and step 2. above really isn't necessary. We can use the browsable() function from htmltools to handle viewing. It worked for me in rstudio and vscode. We only need to turn browsable() on if interactive().

Next we need to introduce a new concept to skimr: render_* functions. As of now, I see render_text (replacing the default print options), render_markdown (replacing the knit print functions) and the new render_html functions. All take a skim_df and two functions: one for rendering the summary and the other for rendering the individual statistics tables. With these, the user will get much more granular options for customizing output. I think this is really important for the html varieties, since there are so many options within gt.

These functions will be generic. You should be able to call them on a complete skim_df, a skim_list (what you get from partition) and one_skim_df (the contents from partition).

Otherwise, the last bit of this will be to clean up the summary. Right now, the summary generates the object and does some of the printing in the same step. We'll need to handle that in separate functions, so that we'll have more options for summary printing.

@michaelquinn32
Copy link
Collaborator Author

Another extension here is to produce the results as an html widget. Then, for example, we could put each table (summary + stats for each type) within a tabset.
https://dev.to/imiahazel/pure-html-css-tabs-2p60

Supporting that means our option for output type shouldn't just be boolean, but support multiple text values. Closer to an enum.

@elinw
Copy link
Collaborator

elinw commented Dec 31, 2021 via email

@michaelquinn32 michaelquinn32 changed the title Better integration with the gt package Html output in the R viewer (i.e. Better integration with the gt package) Jan 18, 2022
@olivroy
Copy link

olivroy commented May 11, 2023

@michaelquinn32

I have a suggestion for 1.

gt_captioned <- function(x, name) gt::gt(x, caption = name)

skim(iris) %>%
  partition() %>%
  purrr::imap(gt_captioned) %>%
  htmltools::tagList() %>%
  htmltools::browsable()

I'd be interested to see more!

On my side, I did further modifications to improve the display, such as pct formatting, and auto formatting on gt side. It is out of scope for skimr though..

        gt_skim <- function(data, type) {
          gt::gt(data, caption = type) |>
            gt::fmt_auto(lg_num_pref = "suf") |>
            gt::fmt_percent(
              columns = any_of("complete_rate"),
              drop_trailing_zeros = TRUE, 
             decimals = 1
            )
        }

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

No branches or pull requests

3 participants