{epoxy}

super glue for data-driven reports and Shiny apps

Garrick Aden-Buie

posit::conf(2023)

Infant day care costs
up to $15,417 a year

Infant day care costs

up to 

Infant day care costs

up to
$15,417
a year

report.Rmd

```{r}
max_med_cost <-
  childcare_costs |>
  # group and summarize… |>
  filter(cost = max(cost)) |>
  pull(cost)  
```

Infant day care costs

up to 
 

report.Rmd

```{r}
max_med_cost <-
  childcare_costs |>
  # group and summarize… |>
  filter(cost = max(cost)) |>
  pull(cost)  
```

Infant day care costs
up to
`r max_med_cost`
a year.

Report: Childcare Costs

Infant day care costs
up to 1.541696^{4}
a year.

Report: Childcare Costs

Infant day care costs
up to $15,416
a year.

  • Inline syntax
  • Just-in-time formatting
  • Reusable templates

  • Made for developers
  • Very light-weight
  • Files that end in .R

  • Made for data scientists
  • Using familiar packages
  • Scripts, reports, apps

 
Infant day care costs
up to `r max_med_cost`
a year.
 

```{epoxy}
Infant day care costs
up to `r max_med_cost`
a year.
```

```{epoxy}
Infant day care costs
up to `r max_med_cost`
a year.
```

```{epoxy}
Infant day care costs
up to {max_med_cost}
a year.
```

```{epoxy}
Infant day care costs
up to {.dollar max_med_cost}
a year.
```

Infant day care costs
up to $15,417 a year

glue(
  "{max_med_cost}"
)
#> 15416.96

glue(
  "{max_med_cost}",
  .transformer = identity_transformer
)
#> 15416.96

glue(
  "{max_med_cost}",
  .transformer = epoxy_transform_inline()
)
#> 15416.96

glue(
  "{.dollar max_med_cost}",
  .transformer = epoxy_transform_inline()
)
#> $15,416.96

epoxy("{.dollar max_med_cost}")
#> $15,416.96

Inline epoxy transformers

{.dollar max_med_cost} 1.541696^{4} $15,416.96

{.percent mhi_pct} 0.2376447 24%

{.comma county_pop_med} 1.595192^{6} 1,595,192

{.ordinal cost_rank} 1 1st

{.titlecase age} infant Infant

{.bold county_size} very large very large

{.italic type} day care day care

```{epoxy cost-summary}
{.titlecase age} {.italic type}
in {.bold county_size} counties
ranks {.ordinal cost_rank} in childcare costs
at {.dollar max_med_cost} per year,
or {.percent mhi_pct} of median household income.
```

Infant day care in very large counties ranks 1st in childcare costs at $15,416.96 per year, or 24% of median household income.

epoxy_transform_set(
  .cpm = function(x) x / 12
)

```{epoxy cost-summary}
{.titlecase age} {.italic type}
in {.bold county_size} counties
ranks {.ordinal cost_rank} in childcare costs
at {.dollar max_med_cost} per year,
about {.cpm max_med_cost} per monthabout {.dollar {.cpm max_med_cost}} per month
or {.percent mhi_pct} of median household income.
```

Infant day care in very large counties ranks 1st in childcare costs at $15,416.96 per year, about 1284.75 per month about $1,284.75 per month or 24% of median household income.

epoxy_transform_set(
  .cpm = function(x) x / 12,
  .dollar = scales::label_dollar(),
  .percent = scales::label_percent()
)

Infant day care in very large counties ranks 1st in childcare costs at $15,416.96 per year, about $1,284.75 per month or 24% of median household income.

epoxy_transform_set(
  .cpm = function(x) x / 12,
  .dollar = scales::label_dollar(accuracy = 100),
  .percent = scales::label_percent(accuracy = 0.1)
)

Infant day care in very large counties ranks 1st in childcare costs at $15,400 per year, about $1,300 per month or 23.8% of median household income.

childcare_summary
#> # A tibble: 10 × 9
#>    cost_rank county_size type      age        max_med_cost mhi_2018 county_pop_med n_counties mhi_pct
#>        <int> <chr>       <chr>     <chr>             <dbl>    <dbl>          <dbl>      <int>   <dbl>
#>  1         1 very large  day care  infant           15417.    64874        1595192         37   0.238
#>  2         2 large       day care  infant           13420.    68021         703619         77   0.197
#>  3         3 very large  day care  toddler          12121.    64874        1595192         37   0.187
#>  4         4 large       day care  toddler          11180     68021         703619         77   0.164
#>  5         5 very large  day care  preschool        11050     64874        1595192         37   0.170
#>  6         6 mid-sized   day care  infant           10194.    58775         179085        353   0.173
#>  7         7 large       day care  preschool        10078.    68021         703619         77   0.148
#>  8         8 very large  home care infant            9892.    64874        1595192         37   0.152
#>  9         9 very large  day care  school-age        9199.    64874        1595192         37   0.142
#> 10        10 very large  home care toddler           9100     64874        1595192         37   0.140

```{epoxy cost-summary, .data = childcare_summary[1, ]}
{.titlecase age} {.italic type}
in {.bold county_size} counties
ranks {.ordinal cost_rank} in childcare costs
at {.dollar max_med_cost} per year,
about {.dollar {.cpm max_med_cost}} per month
or {.percent mhi_pct} of median household income.
```

Infant day care in very large counties ranks 1st in childcare costs at $15,400 per year, about $1,300 per month or 23.8% of median household income.

```{epoxy cost-summary, .data = childcare_summary[8, ]}
{.titlecase age} {.italic type}
in {.bold county_size} counties
ranks {.ordinal cost_rank} in childcare costs
at {.dollar max_med_cost} per year,
about {.dollar {.cpm max_med_cost}} per month
or {.percent mhi_pct} of median household income.
```

Infant home care in very large counties ranks 8th in childcare costs at $9,900 per year, about $800 per month or 15.2% of median household income.

childcare_summary |>
  dplyr::filter(
    age == "infant",
    type == "home care",
    county_size == "very large"
  ) |>
  epoxy_use_chunk(label = "cost-summary")

Infant home care in very large counties ranks 8th in childcare costs at $9,900 per year, or 15.2% of median household income.

report-html.Rmd

```{epoxy_htmlepoxy_html}
in {{@bold county_size}}{{@bold county_size}} counties
```
in <strong><strong>very large</strong></strong> counties

report-latex.Rmd

```{epoxy_latexepoxy_latex}
in <<.bold county_size>><<.bold county_size>> counties
```
in \textbf{very large} counties

R Console

epoxy("{.dollar {.cpm max_med_cost}} per month")
#> $1,300 per month

epoxy_html("{{@dollar {{@cpm max_med_cost }} }} per month")
#> $1,300 per month

epoxy_latex("<<.dollar <<.cpm max_med_cost>> >> per month")
#> $1,300 per month

epoxy_use_file(file = "cpm-snippet.md")
#> $1,300 per month

  • {epoxy} in Reports
    • R Markdown and Quarto
    • Markdown, HTML, or LaTeX
  • {epoxy} in scripts
    • epoxy()
    • epoxy_html()
    • epoxy_latex()

Shiny

library(shiny)
library(bslib)

ui <- page_fixed(
  textInput("greetings", "Greeting", "Hello"),
  textInput("company", "Company", "rstudio"),
  textInput("year", "Year", "2023"),
  ui_epoxy_html(
    .id = "hello",
    p(
      "{{greetings}}, {{company}}::conf({{year}})!"
    )
  )
)

server <- function(input, output, session) {
  output$hello <- render_epoxy(
    greetings = input$greetings,
    company = input$company,
    year = input$year
  )
}

shinyApp(ui, server)

  • Blend data and prose

  • Reusable templates

  • Just-in-time formatting

  • Reports, scripts and apps

pkg.garrickadenbuie.com/epoxy

grrrck@fosstodon.org