reactablefmtr R Package

repository·main·Indexed 42 days ago

https://github.com/kcuilla/reactablefmtr

An R package that enhances {reactable} with conditional formatters, themes, and data visualizations. Features include data bars via `data_bars()`, interactive sparklines and sparkbars via `react_sparkline()` and `react_sparkbar()`, color scales with `color_scales()`, and bubble grids with `bubble_grid()`. It provides over 24 custom themes and utilities for adding titles, subtitles, and sources, as well as exporting tables to PNG or HTML using `save_reactable()`.

Tokens
918
Snippets
8
Records
8
Agent score
3%

What's inside reactablefmtr

  1. Apply custom themes to tables

    main

    The package includes over 24 custom themes, including Bootstrap themes and styles inspired by news/sports sites like The New York Times, FiveThirtyEight, and ESPN. Themes can be applied to any {reactablefmtr} or {reactable} table by referencing the theme name.

    # Example: applying a theme
    # reactable(data, theme = fivethirtyeight())
  2. Install reactablefmtr

    main

    You can install the stable version of reactablefmtr from CRAN, or install the development version from GitHub using remotes.

    # Install from CRAN
    install.packages("reactablefmtr")
    
    # Install development version from GitHub
    remotes::install_github("kcuilla/reactablefmtr")
  3. Apply color scales to cells

    main

    Use color_scales() to assign conditional colors to cells based on their relative values. The text color automatically adjusts to maintain readability against the cell's background color.

    # Use color_scales() within colDef(cell = ...)
  4. Add data bars to reactable tables

    main

    Use the data_bars() function to assign horizontal bars to rows. This is a much simpler alternative to manually writing HTML/CSS for bar charts within reactable. The bars animate automatically when the table is sorted. You can customize alignment, text position, icons, and images.

    library(reactablefmtr)
    
    reactable(
      data,
      defaultColDef = colDef(
        cell = data_bars(data, text_position = "outside-base")
      )
    )
  5. Save tables as PNG or HTML

    main

    Use save_reactable() to export your tables. You can save them as static PNG images or interactive HTML files. If you are working in an R Markdown document with custom CSS, you can pass the .Rmd filename to save_reactable() to capture the styling.

    # Save as PNG
    save_reactable(table_name, "table.png")
    
    # Save as HTML
    save_reactable(table_name, "table.html")
    
    # Using a pipe
    table_name %>%
      save_reactable("table.png")
    
    # Saving from R Markdown with custom CSS
    save_reactable("table_name.Rmd", "table.png")
  6. Add titles, subtitles, and sources to tables

    main

    You can easily add metadata to your tables using add_title(), add_subtitle(), and add_source(). These functions allow for customization of alignment, font size, font family, font style, and font color.

    reactable(iris[10:29, ]) %>%
      add_title("This is a title") %>%
      add_subtitle("This is a subtitle") %>%
      add_source("This is a source")
  7. Create interactive sparklines and sparkbars

    main

    Use react_sparkline() for line sparklines or react_sparkbar() for sparkline bar charts. These are interactive: hovering over data points reveals their values.

    Note: These features are imported from the {dataui} package, which must be installed from GitHub to use this functionality.

    # Use react_sparkline() or react_sparkbar()