Skip to contents

You can use the output of narrator in HTML reports or shiny with additional formatting that can be added using format_pct() and add_tag() functions. If the output is a named list, which is a default behaviour of the narrate_* functions, names can be used as headers and narratives rendered below.

When using to_html() function you can easily add formatting for tags and percentage to be displayed is any color you choose:

narrative <- sales %>%
  group_by(Region, Product) %>%
  summarise(Sales = sum(Sales, na.rm = TRUE)) %>%
  arrange(desc(Sales)) %>%
  narrate_descriptive()

to_html(narrative)

Total Sales

Total Sales across all Regions is 38790478.4.

Region by Sales

Outlying Regions by Sales are NA (18079736.4, 46.6 %) and EMEA (13555412.7, 34.9 %).

NA by Product

In NA, significant Products by Sales are Food & Beverage (7392821, 40.9 %) and Electronics (3789132.7, 21 %).

EMEA by Product

In EMEA, significant Products by Sales are Food & Beverage (5265113.2, 38.8 %) and Electronics (3182803.4, 23.5 %).

Product by Sales

Outlying Products by Sales are Food & Beverage (15543469.7, 40.1 %) and Electronics (8608962.8, 22.2 %).
to_html(narrative, title_tag = "h5", positive = "purple")
Total Sales
Total Sales across all Regions is 38790478.4.
Region by Sales
Outlying Regions by Sales are NA (18079736.4, 46.6 %) and EMEA (13555412.7, 34.9 %).
NA by Product
In NA, significant Products by Sales are Food & Beverage (7392821, 40.9 %) and Electronics (3789132.7, 21 %).
EMEA by Product
In EMEA, significant Products by Sales are Food & Beverage (5265113.2, 38.8 %) and Electronics (3182803.4, 23.5 %).
Product by Sales
Outlying Products by Sales are Food & Beverage (15543469.7, 40.1 %) and Electronics (8608962.8, 22.2 %).

Narrator will also convert the output from Chat GPT and replace the new lines with a double <br> tag to ensure it is correctly indexed.

"The Total Sales across all Products amounted to an impressive $11,381,210.7, with Home and Tools emerging as the top performing categories by Sales with $4,599,370.9 (40.4%) and $4,404,196.7 (38.7%) respectively.\n\nFurther analysis reveals that in the Home category, the North American (NA) and Europe, Middle East and Africa (EMEA)." %>%
  to_html()
The Total Sales across all Products amounted to an impressive $11,381,210.7, with Home and Tools emerging as the top performing categories by Sales with $4,599,370.9 (40.4 %) and $4,404,196.7 (38.7 %) respectively.

Further analysis reveals that in the Home category, the North American (NA) and Europe, Middle East and Africa (EMEA).