purrr

Generate custom html per row of a data frame with pmap

Here is one way to generate dynamic html for your Shiny app from a reactive data frame using my favorite tidyverse package purrr and specifically the pmap function. I’ve created a shiny app that uses the starwars dataset included with dplyr. The user selects a species from a drop down. Then for each character who belongs to that species some sweet html is generated that displays their name in a <h1> tag, their home planet in a <h2> tag and their species in a <h3> tag.

Guards! Guards! purrr::map_if

I found a cool use for purrr’s map_if function recently that both felt wizardly and helped me better understand when to use map_if. Problem: I had a list called params with 3 items of different types start_date - a Date end_date - a Date confidence_interval - a Numeric params <- list( start_date = as.Date("2015-01-01"), end_date = as.Date("2015-12-31"), confidence_interval = 0.8 ) params ## $start_date ## [1] "2015-01-01" ## ## $end_date ## [1] "2015-12-31" ## ## $confidence_interval ## [1] 0.