| Title: | Shiny Interface, Chart Options and Report Builder for DataSuite Apps |
|---|---|
| Description: | The shared interface of DataSuite's Shiny apps: chart options that restyle any 'ggplot2' chart (texts, fonts, colours, axes, legend, show or hide an element), a Word-like report builder writing Word, PowerPoint and PDF files, and the Shiny and React components, page frame and navigation the apps are built from. It holds nothing specific to one app's data: an app gives it its pages, its charts and its data through small interfaces. |
| Authors: | David Kariuki [aut, cre] (ORCID: <https://orcid.org/0009-0003-6159-1107>), African Population and Health Research Center (APHRC) [cph, fnd] |
| Maintainer: | David Kariuki <hello@damurka.com> |
| License: | AGPL (>= 3) |
| Version: | 0.5.2 |
| Built: | 2026-10-11 22:22:48 UTC |
| Source: | https://github.com/damurka/datasuite.ui |
The shared interface of DataSuite's Shiny apps: chart options that restyle any 'ggplot2' chart (texts, fonts, colours, axes, legend, show or hide an element), a Word-like report builder writing Word, PowerPoint and PDF files, and the Shiny and React components, page frame and navigation the apps are built from. It holds nothing specific to one app's data: an app gives it its pages, its charts and its data through small interfaces.
An app built on datasuite.ui gives it its pages, its data and its report content through small interfaces; the
package itself knows nothing about any app's data and never calls an app's own package. The Countdown to 2030 apps
are the working example: cd2030.core adds the Countdown pages and report content on top of it, and each app package
(cd2030.rmncah, cd2030.vaxx, cd2030.pooled) has a run_app() built from both.
app_frame() builds a whole app: the page, the sidebar and header, and the server. An app gives it a page registry
(cd_page_def(), cd_use_pages()), a nav tree (cd_nav_section(), cd_nav_item()) and a data_server returning
its dataset. A page is a module whose UI is cd_page_ui(), made of cards (cd_card(), cd_chart_card()), charts
with their download and Customize tools (cd_plot_ui(), cd_plot_server()), inputs, dialogs and feedback. Every
kit function is listed in ?"interface-kit"; the package README (the dataset contract, a minimal app) and
docs/COMPONENTS.md in the repository describe each one.
cd_chart_options() describes how a ggplot2 chart should look (texts, fonts, colours, axes, legend, grid, facets,
marks, and showing or hiding each element) and apply_chart_options() applies it to a finished chart.
merge_chart_options(), resolve_chart_options(), chart_option_fields() and cd_chart_type() support them.
A report is blocks on pages with a theme and a cover, edited in the browser (the Reports page, reports_ui() /
reports_server()) and exported with export_report() (Word, PDF) or export_deck() (PowerPoint, PDF). An app
registers what its reports offer once with report_register() (kinds of chart and table, standard reports, themes,
fields) and gives the engine one dataset's data as a report_context(), or through an as_report_context() method
for its own dataset class. Themes: report_themes(), report_theme_from_file(); fields: report_field_catalog().
Text is a translation key. cd_translations() merges the kit's keys, the files packages registered with
cd_register_translations() and the app's own file for shiny.i18n::init_i18n(); cd_use_i18n() makes the
translator the one the components use.
Maintainer: David Kariuki hello@damurka.com (ORCID)
Other contributors:
African Population and Health Research Center (APHRC) [copyright holder, funder]
Useful links:
Report bugs at https://github.com/damurka/datasuite.ui/issues
Apps built with app_frame() answer requests from DataSuite's chat (see docs/AI-BRIDGE.md). The frame has the
built-in actions (the page, its charts and tables, navigation); an app adds its own with ai_action(), passed in
app_frame(ai_actions = ).
ai_action( name, fn, kind = c("read", "view", "add", "replace", "change"), description = "", args = list(), classify = NULL, summary = NULL )ai_action( name, fn, kind = c("read", "view", "add", "replace", "change"), description = "", args = list(), classify = NULL, summary = NULL )
name |
The action's name, e.g. |
fn |
|
kind |
How much the action changes, which decides whether DataSuite asks the user first:
|
description |
One sentence telling the AI what the action does. |
args |
A named list describing each argument, |
classify |
Optional |
summary |
Optional |
An ai_action object.
ai_action("highlight", function(args, session) list(done = TRUE), kind = "view", description = "Highlight a region on the map", args = list(region = "a region name"))ai_action("highlight", function(args, session) list(done = TRUE), kind = "view", description = "Highlight a region on the map", args = list(region = "a region name"))
Registers a chart or table so DataSuite's chat can list it, read the data it shows and screenshot it (see
docs/AI-BRIDGE.md). cd_plot_server() does this for every chart; call it for other outputs, e.g. a table, from
their module server.
ai_register_component( session, output_id, type = c("chart", "table"), data, about = NULL, id = sub("-$", "", session$ns("")) )ai_register_component( session, output_id, type = c("chart", "table"), data, about = NULL, id = sub("-$", "", session$ns("")) )
session |
The module's session. |
output_id |
The output's full id ( |
type |
|
data |
A function (or reactive) returning the data frame the output shows. It is only called when the AI asks for the data, never to fill in the state. |
about |
What the output is, for the app's AI: |
id |
The component's id; by default the module path ( |
NULL, invisibly.
A change the app asks the browser to make (open a page, set a filter) only shows in input after a round trip. An
ai_action() returns ai_reply_when() to answer when ready() is TRUE, or after timeout seconds, with
result().
ai_reply_when(ready, result, timeout = 3)ai_reply_when(ready, result, timeout = 3)
ready |
A function returning |
result |
A function returning the result to send. |
timeout |
Seconds to wait at most. |
An object ai_action() functions return.
Changes only what options sets (see cd_chart_options() for the list). The plot passed in is not modified. A plot that
is not a ggplot (base graphics) is returned unchanged.
apply_chart_options(p, options = NULL)apply_chart_options(p, options = NULL)
p |
A ggplot. |
options |
A |
The ggplot.
What every report function calls on its first argument. A report_context is returned as it is and NULL gives an
empty one; an app adds a method for its own dataset class.
as_report_context(x, ...)as_report_context(x, ...)
x |
A report context, |
... |
Passed to methods. |
A report_context.
Describes what a user can change about a chart: its texts, fonts, sizes, colours, angles, legend, axes, grid,
backgrounds and how its lines, points and labels are drawn. Every plot method in the package accepts one through its
options argument (and any of these fields as a named argument in ...), and an app can keep them per chart, so
the choices survive reloads.
cd_chart_options( ..., title = NULL, subtitle = NULL, caption = NULL, tag = NULL, x_title = NULL, y_title = NULL, legend_title = NULL, title_wrap = NULL, font_family = NULL, text_scale = NULL, line_height = NULL, title_size = NULL, subtitle_size = NULL, caption_size = NULL, axis_title_size = NULL, axis_text_size = NULL, x_title_size = NULL, y_title_size = NULL, x_text_size = NULL, y_text_size = NULL, legend_title_size = NULL, legend_text_size = NULL, strip_text_size = NULL, title_face = NULL, subtitle_face = NULL, caption_face = NULL, axis_title_face = NULL, axis_text_face = NULL, legend_title_face = NULL, legend_text_face = NULL, strip_text_face = NULL, text_color = NULL, title_color = NULL, subtitle_color = NULL, caption_color = NULL, axis_title_color = NULL, axis_text_color = NULL, legend_title_color = NULL, legend_text_color = NULL, strip_text_color = NULL, title_align = NULL, subtitle_align = NULL, caption_align = NULL, title_position = NULL, caption_position = NULL, x_text_angle = NULL, y_text_angle = NULL, plot_margin = NULL, legend_position = NULL, legend_direction = NULL, legend_justification = NULL, legend_ncol = NULL, legend_nrow = NULL, legend_reverse = NULL, legend_key_size = NULL, legend_background = NULL, legend_labels = NULL, legend_label_wrap = NULL, category_labels = NULL, category_label_wrap = NULL, x_limits = NULL, y_limits = NULL, x_labels = NULL, y_labels = NULL, axis_line = NULL, axis_line_color = NULL, axis_ticks = NULL, flip = NULL, grid = NULL, grid_minor = NULL, grid_color = NULL, grid_linewidth = NULL, grid_linetype = NULL, panel_border = NULL, panel_border_color = NULL, panel_color = NULL, background_color = NULL, strip_background = NULL, legend_border = NULL, legend_border_color = NULL, strip_border = NULL, strip_border_color = NULL, theme_preset = NULL, colors = NULL, line_scale = NULL, point_scale = NULL, alpha = NULL, bar_width = NULL, label_size = NULL, label_angle = NULL, label_color = NULL, facet_ncol = NULL, facet_nrow = NULL, facet_scales = NULL, strip_position = NULL, show_title = NULL, show_subtitle = NULL, show_caption = NULL, show_x_title = NULL, show_y_title = NULL, show_x_text = NULL, show_y_text = NULL, show_legend = NULL, show_legend_title = NULL, show_labels = NULL, show_strips = NULL )cd_chart_options( ..., title = NULL, subtitle = NULL, caption = NULL, tag = NULL, x_title = NULL, y_title = NULL, legend_title = NULL, title_wrap = NULL, font_family = NULL, text_scale = NULL, line_height = NULL, title_size = NULL, subtitle_size = NULL, caption_size = NULL, axis_title_size = NULL, axis_text_size = NULL, x_title_size = NULL, y_title_size = NULL, x_text_size = NULL, y_text_size = NULL, legend_title_size = NULL, legend_text_size = NULL, strip_text_size = NULL, title_face = NULL, subtitle_face = NULL, caption_face = NULL, axis_title_face = NULL, axis_text_face = NULL, legend_title_face = NULL, legend_text_face = NULL, strip_text_face = NULL, text_color = NULL, title_color = NULL, subtitle_color = NULL, caption_color = NULL, axis_title_color = NULL, axis_text_color = NULL, legend_title_color = NULL, legend_text_color = NULL, strip_text_color = NULL, title_align = NULL, subtitle_align = NULL, caption_align = NULL, title_position = NULL, caption_position = NULL, x_text_angle = NULL, y_text_angle = NULL, plot_margin = NULL, legend_position = NULL, legend_direction = NULL, legend_justification = NULL, legend_ncol = NULL, legend_nrow = NULL, legend_reverse = NULL, legend_key_size = NULL, legend_background = NULL, legend_labels = NULL, legend_label_wrap = NULL, category_labels = NULL, category_label_wrap = NULL, x_limits = NULL, y_limits = NULL, x_labels = NULL, y_labels = NULL, axis_line = NULL, axis_line_color = NULL, axis_ticks = NULL, flip = NULL, grid = NULL, grid_minor = NULL, grid_color = NULL, grid_linewidth = NULL, grid_linetype = NULL, panel_border = NULL, panel_border_color = NULL, panel_color = NULL, background_color = NULL, strip_background = NULL, legend_border = NULL, legend_border_color = NULL, strip_border = NULL, strip_border_color = NULL, theme_preset = NULL, colors = NULL, line_scale = NULL, point_scale = NULL, alpha = NULL, bar_width = NULL, label_size = NULL, label_angle = NULL, label_color = NULL, facet_ncol = NULL, facet_nrow = NULL, facet_scales = NULL, strip_position = NULL, show_title = NULL, show_subtitle = NULL, show_caption = NULL, show_x_title = NULL, show_y_title = NULL, show_x_text = NULL, show_y_text = NULL, show_legend = NULL, show_legend_title = NULL, show_labels = NULL, show_strips = NULL )
... |
|
title, subtitle, caption, tag
|
Chart texts. |
x_title, y_title
|
Axis titles. |
legend_title |
Legend title. |
title_wrap |
Wrap the title, subtitle and caption after this many characters. |
font_family |
A font family available on the machine drawing the chart (e.g. |
text_scale |
A multiplier for every text size in the chart ( |
line_height |
Line spacing of text (a multiple of the font size, default about |
title_size, subtitle_size, caption_size, axis_title_size, axis_text_size, legend_title_size, legend_text_size, strip_text_size
|
Text sizes in points. |
x_title_size, y_title_size, x_text_size, y_text_size
|
Size of one axis' title or tick labels. |
title_face, subtitle_face, caption_face, axis_title_face, axis_text_face, legend_title_face, legend_text_face, strip_text_face
|
One of |
text_color |
Colour of all text; the |
title_color, subtitle_color, caption_color, axis_title_color, axis_text_color, legend_title_color, legend_text_color, strip_text_color
|
Colour of one kind of text. |
title_align, subtitle_align, caption_align
|
One of |
title_position, caption_position
|
|
x_text_angle, y_text_angle
|
Angle of the tick labels in degrees (e.g. |
plot_margin |
Space around the chart in points: one number, or four (top, right, bottom, left). |
legend_position |
One of |
legend_direction |
|
legend_justification |
Where the legend sits along its side: |
legend_ncol, legend_nrow
|
Number of columns or rows the legend entries are laid out in. |
legend_reverse |
|
legend_key_size |
Size of the legend keys in millimetres. |
legend_background |
Fill colour of the legend box. |
legend_labels |
A named character vector (or list): names are the legend entries the plot draws (or the text currently shown for them), values the text to show instead. |
legend_label_wrap |
Wrap the legend entries after this many characters. |
category_labels |
The same as |
category_label_wrap |
Wrap the category labels after this many characters. |
x_limits, y_limits
|
Two numbers ( |
x_labels, y_labels
|
How numbers on a continuous axis are written: |
axis_line |
|
axis_line_color |
Colour of the axis lines. |
axis_ticks |
|
flip |
|
grid |
Which grid lines to show: |
grid_minor |
|
grid_color, grid_linewidth, grid_linetype
|
Style of the grid lines ( |
panel_border |
|
panel_border_color |
Colour of that border. |
panel_color |
Fill colour of the plotting area. |
background_color |
Fill colour of the whole chart. |
strip_background |
Fill colour of facet strips. |
legend_border, strip_border
|
|
legend_border_color, strip_border_color
|
Colour of that border. |
theme_preset |
Start from a different look before the other options are applied: |
colors |
A named character vector of colours for a colour or fill legend (names are entries as in
|
line_scale, point_scale
|
Multiply the width of lines and the size of points ( |
alpha |
Transparency of every mark, from |
bar_width |
Width of the bars (and boxes) as a share of the space each has, above |
label_size |
Size in points of text drawn on the chart (data labels). |
label_angle, label_color
|
Angle and colour of that text. |
facet_ncol, facet_nrow
|
For a chart split into panels with |
facet_scales |
Whether panels share their axes: |
strip_position |
Where the panel labels (strips) go: |
show_title, show_subtitle, show_caption, show_x_title, show_y_title, show_x_text, show_y_text, show_legend, show_legend_title, show_labels, show_strips
|
Show or hide one element of the chart: the title, subtitle, caption, an axis title, an axis' tick labels
( |
A field left NULL means "keep what the plot draws by default"; only what is set is changed. Text fields accept "",
which hides that text and the space it took (as the show_* fields do). Colours are anything R understands ("red", "#1b7837", "transparent"). Sizes are in points
unless said otherwise. x_* and y_* always mean the data's x and y aesthetics, so they follow the data when the chart
is flipped.
An object of class cd_chart_options (a list of the fields that are set).
apply_chart_options(), merge_chart_options()
cd_chart_options(title = "Coverage", legend_position = "bottom", text_scale = 1.2) cd_chart_options(x_title = "Year", legend_labels = c(dhis2 = "Routine data")) cd_chart_options(x_text_angle = 45, grid = "horizontal", grid_color = "grey90", y_labels = "percent_points")cd_chart_options(title = "Coverage", legend_position = "bottom", text_scale = 1.2) cd_chart_options(x_title = "Year", legend_labels = c(dhis2 = "Routine data")) cd_chart_options(x_text_angle = 45, grid = "horizontal", grid_color = "grey90", y_labels = "percent_points")
A key made from the geoms a ggplot is built from (lines and points, bars, tiles...), used for a chart that has no id of its own.
cd_chart_type(p)cd_chart_type(p)
p |
A ggplot. |
A string such as "geom:Errorbar+Line+Point", or NULL when p is not a ggplot with layers.
The page assembled from its parts. Modules do not call this directly; they call cd_page_ui(), which fills in the title, section and subtitle from the page registry.
cd_page_body( dashboardId, dashboardTitle, i18n, ..., filters = NULL, include_report = FALSE, include_notes = FALSE, include_help = TRUE, eyebrow = NULL, subtitle = NULL, include_denominator = FALSE )cd_page_body( dashboardId, dashboardTitle, i18n, ..., filters = NULL, include_report = FALSE, include_notes = FALSE, include_help = TRUE, eyebrow = NULL, subtitle = NULL, include_denominator = FALSE )
dashboardId |
Unique module ID |
dashboardTitle |
Localized dashboard title |
i18n |
Translator object |
... |
Page content, passed to cd_page_content() |
filters |
Optional cd_filter_bar(...) with the page's filter inputs |
include_report, include_notes, include_help
|
Show the header's report, notes and help buttons. |
eyebrow |
The small label above the title (a translation key). |
subtitle |
The line under the title (a translation key). |
include_denominator |
Show the row the app's page header server fills (Countdown: the denominators). |
An app starts a page's server the first time the page is opened (cd_pages_server()). What needs a page that may
not have been opened (the AI reading a chart on another page) starts it with this. Nothing happens for a page
already started, or in an app whose pages are all started with the session.
cd_start_pages(session = getDefaultReactiveDomain(), which = NULL)cd_start_pages(session = getDefaultReactiveDomain(), which = NULL)
session |
The Shiny session. |
which |
The ids of the pages to start; every page when |
NULL, invisibly.
Tells whether a ggplot is split into panels (facet_wrap() or facet_grid()) and how they are laid out now, so an
editor can offer the panel options of cd_chart_options() (facet_ncol, facet_nrow, facet_scales,
strip_position) only for charts that have panels.
chart_facet_info(plot)chart_facet_info(plot)
plot |
A ggplot (anything else gives |
NULL when the chart has no panels. Otherwise a list with
type: "wrap" or "grid";
ncol, nrow: the number of columns and rows of panels as drawn (integer; NA when the plot cannot be built and
the facet does not say);
scales: "fixed", "free", "free_x" or "free_y";
strip_position: "top", "bottom", "left" or "right" (for facet_grid(), where the column labels are, or
the row labels when it only has rows);
panels: the number of panels (integer, NA when the plot cannot be built).
library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + facet_wrap(~cyl, ncol = 2) chart_facet_info(p) chart_facet_info(ggplot(mtcars, aes(wt, mpg)) + geom_point())library(ggplot2) p <- ggplot(mtcars, aes(wt, mpg)) + geom_point() + facet_wrap(~cyl, ncol = 2) chart_facet_info(p) chart_facet_info(ggplot(mtcars, aes(wt, mpg)) + geom_point())
Every field cd_chart_options() accepts, for code that keeps only the chart options out of a list of settings.
chart_option_fields()chart_option_fields()
A character vector.
What an app asks of DataSuite, the application running it: open the chat, print a page, install packages. Inside a
Jovian R kernel whose host answers it (DataSuite starts the app with CDSUITE_HOST_UI=1), the request goes on
Jovian's host channel as the method "datasuite.<action>" (hera::host_notify(), or hera::host_ask() to wait for
the answer while the app keeps running); otherwise it is one line on the R session's output,
DATASUITE_HOST_REQUEST <json>, with the action in the JSON object beside args, and an answer is read from a
done file named in the request. The requests, their arguments and answers are described in the package's
docs/HOST-REQUESTS.md.
ds_host_request(action, args = list(), wait = FALSE, timeout = 120)ds_host_request(action, args = list(), wait = FALSE, timeout = 120)
action |
The request: |
args |
Its arguments: a named list (a JSON object; give an array as a list, so that one element stays an array). |
wait |
|
timeout |
For |
It asks whenever it is called: a caller checks first that the app runs inside DataSuite (CDSUITE_SHINY_ID is
set, or CDSUITE_PRINT for printing).
With wait = FALSE, TRUE invisibly once the request is sent. With wait = TRUE, DataSuite's answer (a
list, as in the done file: ok, and error when it failed), or NULL when it gave none.
## Not run: ds_host_request("openChat", list(query = "Explain this chart: ")) ## End(Not run)## Not run: ds_host_request("openChat", list(query = "Explain this chart: ")) ## End(Not run)
Draws every chart and table of a deck from the loaded data and writes it as a PowerPoint file, or as a PDF made from
that file (by PowerPoint or LibreOffice, see report_deck_converter()), with the report builder's own writers
(Quire's, through quire::quire_export()). Every item is placed at its box: text as text boxes in the design's fonts
and colours, charts and pictures as pictures, tables as PowerPoint tables. The slides' speaker notes are kept.
export_deck( context, project, file, format = c("pptx", "pdf"), i18n = NULL, progress = NULL, converter = c("auto", "powerpoint", "libreoffice") )export_deck( context, project, file, format = c("pptx", "pdf"), i18n = NULL, progress = NULL, converter = c("auto", "powerpoint", "libreoffice") )
context |
A report context ( |
project |
The deck (see the top of |
file |
The file to write. |
format |
|
i18n |
An object with a |
progress |
A function called with a number between 0 and 1 as the export advances, or |
converter |
What makes the PDF: |
file, invisibly, with attribute converter (what made the PDF; NULL for a PowerPoint file).
Draws every chart and table from the loaded data and writes the report as a Word document or a PDF, with the report
builder's own writers (Quire's, through quire::quire_export()). The PDF is made from the Word file (see
report_converter()), so the two match page for page. A slide deck (kind = "deck") is
written by export_deck(), as a PowerPoint file or a PDF.
export_report( context, project, file, format = c("docx", "pdf", "pptx"), i18n = NULL, subtitle = NULL, progress = NULL, converter = c("auto", "word", "libreoffice", "browser", "powerpoint") )export_report( context, project, file, format = c("docx", "pdf", "pptx"), i18n = NULL, subtitle = NULL, progress = NULL, converter = c("auto", "word", "libreoffice", "browser", "powerpoint") )
context |
A report context ( |
project |
The report: |
file |
The file to write. |
format |
|
i18n |
An object with a |
subtitle |
Not used any more: the cover page has its own subtitle. Kept so older calls work. |
progress |
A function called with a number between 0 and 1 as the export advances, or |
converter |
|
file, invisibly, with attribute converter: what made the PDF ("word", "libreoffice", "browser",
"powerpoint") or, for Word, what finished the file ("word", or NULL).
Later arguments win, field by field; legend_labels, category_labels and colors combine name by name. Use it to
layer a dataset's defaults, a chart's saved options and what the caller passes now.
merge_chart_options(...)merge_chart_options(...)
... |
|
A cd_chart_options object.
merge_chart_options(cd_chart_options(font_family = "serif", title = "A"), cd_chart_options(title = "B"))merge_chart_options(cd_chart_options(font_family = "serif", title = "A"), cd_chart_options(title = "B"))
Draw one chart or table of a report
render_report_block(context, block, i18n = NULL, design = NULL)render_report_block(context, block, i18n = NULL, design = NULL)
context |
A report context ( |
block |
A chart or table block (see the top of this file for its fields). A |
i18n |
An object with a |
design |
The report's design: its palette colours the chart's series (see |
list(type = "plot", value = <ggplot>), list(type = "table", value = <flextable>), or
list(type = "error", message = <text>) when it cannot be drawn with this dataset.
Apply a custom chart's transforms to its data
report_apply_transforms(data, transform = list())report_apply_transforms(data, transform = list())
data |
A data frame. |
transform |
The spec's |
The data frame, transformed. Stops with a message naming a missing column.
d <- data.frame(region = c("A", "B", "A"), year = c(2022, 2022, 2023), anc4 = c(50, 60, 55)) report_apply_transforms(d, list(list(filter = list(year = 2022)), list(select = c("region", "anc4"))))d <- data.frame(region = c("A", "B", "A"), year = c(2022, 2022, 2023), anc4 = c(50, 60, 55)) report_apply_transforms(d, list(list(filter = list(year = 2022)), list(select = c("region", "anc4"))))
The picture a block refers to as "asset:<id>" (see CacheConnection$set_report_asset()), for showing in a browser.
report_asset_data_url(context, id)report_asset_data_url(context, id)
context |
A report context ( |
id |
The picture's id (with or without |
A data: URL, or NULL when the dataset has no such picture.
Worked out from the page (see report_page()): a full-width block spans the text, a half-width one half of it.
Shared by the builder's previews and by the exported files, so the page on screen and the file agree. A block on a
slide carries its box, box = c(width, height) in inches (see report_project_blocks()): it is drawn at that size.
report_block_size(block, design = NULL)report_block_size(block, design = NULL)
block |
A chart or image block. |
design |
The report's design ( |
c(width, height) in inches.
What a standard report is written with. Texts may be plain strings or report_tx().
report_heading(text, level = 1) report_paragraph(text) report_note(text) report_page_break() report_chart( kind, indicator = NULL, admin_level = "national", size = "full", variant = NULL, type = "chart", region = NULL, year = NULL, title = NULL ) report_table(kind, ...) report_questions( ..., title = report_tx("Interpretations", "Interprétations", "Interpretações") )report_heading(text, level = 1) report_paragraph(text) report_note(text) report_page_break() report_chart( kind, indicator = NULL, admin_level = "national", size = "full", variant = NULL, type = "chart", region = NULL, year = NULL, title = NULL ) report_table(kind, ...) report_questions( ..., title = report_tx("Interpretations", "Interprétations", "Interpretações") )
text |
The text: plain for a heading, formatted (a small subset of HTML) for a paragraph or note. |
level |
A heading's level (1 or 2). |
kind, indicator, admin_level, size, variant, region, year, title
|
A chart's or table's kind (one of the registered
kinds, see |
type |
|
... |
For |
A block (a list).
{chart_indicator} and {chart_year} in a text, heading or caption are the indicator (its name, in the report's
language) and the year of the first chart or table after it in the report, so a title above a chart follows the
chart when its indicator or year is changed. {chart_indicators} names the indicators of all the charts and tables
after it up to the next heading ("ANC 4 Visits and Measles 1"), for a heading above charts side by side. A text with
no chart after it keeps the field as typed.
report_chart_fields(blocks, context = NULL, i18n = NULL)report_chart_fields(blocks, context = NULL, i18n = NULL)
blocks |
The report's blocks, in order. |
context |
A report context ( |
i18n |
The report's translations ( |
The blocks, their texts filled.
Each argument is a function; those left out do nothing (no pictures kept, no saved chart options, no fields).
report_context( draw = NULL, asset_get = NULL, asset_set = NULL, chart_options = NULL, fields = NULL, years = NULL, regions = NULL, flag = NULL )report_context( draw = NULL, asset_get = NULL, asset_set = NULL, chart_options = NULL, fields = NULL, years = NULL, regions = NULL, flag = NULL )
draw |
|
asset_get |
|
asset_set |
|
chart_options |
|
fields |
|
years |
|
regions |
|
flag |
|
An object of class report_context.
Microsoft Word (Windows) or LibreOffice. With one of them the PDF has exactly the Word file's pages. (Quire's:
quire::quire_converter().)
report_converter()report_converter()
"word", "libreoffice", or NULL when neither is installed.
Microsoft PowerPoint (Windows) or LibreOffice. (Quire's: quire::quire_converter().)
report_deck_converter()report_deck_converter()
"powerpoint", "libreoffice", or NULL when neither is installed.
Where a new slide's placeholders go, as PowerPoint places them: each layout lists its boxes as fractions (0 to 1) of the slide's width and height, so they fit a 16:9 or a 4:3 slide.
report_deck_layouts(lang = NULL)report_deck_layouts(lang = NULL)
lang |
|
A list of layouts, each list(id, name, items); each item is list(role, type, x, y, w, h) with role
"title", "subtitle", "heading", "body" or "picture" (a picture placeholder: nothing is written for it
until a picture is put in it), and type "text" (a text box) or "content" (a text, chart, table or picture).
The default cover page
report_default_cover()report_default_cover()
A cover (see the top of R/report-theme.R for its fields).
The default report design
report_default_design()report_default_design()
A design (see the top of R/report-theme.R for its fields).
The report's own (title, date, editors, region, years, the chart below), then those the app registered
(report_register(), fields).
report_field_catalog()report_field_catalog()
A list of list(key, group, label); key is the word written in braces.
The values of a report's fields
report_fields(context, project, date = Sys.Date(), lang = "en")report_fields(context, project, date = Sys.Date(), lang = "en")
context |
A report context ( |
project |
The report ( |
date |
The date the report is dated. |
lang |
The report's language ( |
A named list of strings, one per field in report_field_catalog() that has a value.
Writes the Word file, makes the PDF from it and renders each page as a picture: what the builder's "Final pages" view
shows. Needs Microsoft Word or LibreOffice (report_converter()). For a slide deck, the PowerPoint file and its PDF
(PowerPoint or LibreOffice, report_deck_converter()): one picture per slide.
report_final_pages(context, project, i18n = NULL, dpi = 60, progress = NULL)report_final_pages(context, project, i18n = NULL, dpi = 60, progress = NULL)
context |
A report context ( |
project |
The report: |
i18n |
An object with a |
dpi |
Resolution of the page pictures. |
progress |
A function called with a number between 0 and 1 as the export advances, or |
list(pages = <character vector of PNG files>, converter, pdf = <path>). The files are in a temporary folder
the caller removes.
Downloaded once from flagcdn.com and kept in the package's context folder. NULL when the country is not known or the
flag cannot be downloaded (no internet): the cover is then drawn without it.
report_flag_file(iso3)report_flag_file(iso3)
iso3 |
The country's ISO3 code. |
The path of a PNG file, or NULL.
Typefaces made for print that come with Microsoft Office, so the page in the editor, the charts, the Word file and the PDF all use the same letters, on any computer that opens the file: serif faces for reading text, then sans serif faces for charts, tables and headings. Only those installed where the charts are drawn are given (all of them when that cannot be told).
report_fonts(group = c("all", "serif", "sans"), installed = TRUE)report_fonts(group = c("all", "serif", "sans"), installed = TRUE)
group |
|
installed |
|
A character vector.
Every report_tx() in x (a block, a list of blocks, a cover...) replaced by its text in lang.
report_in(x, lang = "en")report_in(x, lang = "en")
x |
Anything holding texts made with |
lang |
The language. |
x in that language.
One kind of chart or table
report_kind( type, group, label, indicators = NULL, levels = NULL, variants = NULL, year = FALSE, regional = FALSE, groups = NULL, tall = FALSE )report_kind( type, group, label, indicators = NULL, levels = NULL, variants = NULL, year = FALSE, regional = FALSE, groups = NULL, tall = FALSE )
type |
|
group |
The group it is shown under in the builder. |
label |
Its name. |
indicators |
The indicators it can be drawn for (a character vector, an app-defined keyword, or |
levels, variants
|
The levels (e.g. national, regional) and variants it offers. |
year |
Whether a year is chosen. |
regional |
Whether it is drawn for one region. |
groups |
The app's groups of indicators it is for. |
tall |
Whether it is drawn taller than wide (maps, charts with a panel per district), see |
A list.
The saved reports, as the AI lists them
report_list(projects)report_list(projects)
projects |
The saved reports, a named list by id (a dataset's |
A list, the last edited first, of list(id, name, kind, lang, blocks, updated); kind is "report" (a
document) or "deck" (a slide deck), blocks the number of blocks (a deck's: of its slides' items).
report_list(list(r1 = list(name = "Coverage", blocks = list(report_paragraph("Hello")))))report_list(list(r1 = list(name = "Coverage", blocks = list(report_paragraph("Hello")))))
Field by field, b over a: lists such as a cover's editors or logos are replaced whole, not merged item by item.
report_merge(a, b)report_merge(a, b)
a, b
|
Two designs or covers. |
The merged list.
Page size, margins and the width and height left for content. Shared by the builder and the exported files.
report_page(design = report_default_design())report_page(design = report_default_design())
design |
A design. |
A list: width, height, top, bottom, left, right, text_width, text_height.
Generic: a table in, a ggplot out. Chart options (the customize panel) apply to the result like to any other chart.
report_plot_spec(data, plot, title = NULL)report_plot_spec(data, plot, title = NULL)
data |
The (transformed) data frame. |
plot |
The plot description (see |
title |
A title, used when |
A ggplot.
d <- data.frame(region = c("A", "B"), value = c(55, 61)) report_plot_spec(d, list(geom = "col", x = "region", y = "value", percent = TRUE))d <- data.frame(region = c("A", "B"), value = c(55, 61)) report_plot_spec(d, list(geom = "col", x = "region", y = "value", percent = TRUE))
A document's blocks, or every item's block of a slide deck, in order, so a caller can count, check or draw them
the same way for both. A slide item's block gets the item's id and its box (box = c(width, height), inches), which
report_block_size() draws it at. A document's free-layout page (a block of type "canvas", whose items are
placed like a slide's) is given as its items' blocks, in the same way; the canvas block itself is not in the list.
report_project_blocks(project)report_project_blocks(project)
project |
A report ( |
A list of blocks.
Every block in order, compactly: its id and type; a heading's, paragraph's or note's text (plain, the formatting
left out); a chart's or table's kind, settings, chart options and layout, and – with data = TRUE – a short table
of what it shows (drawn as the report draws it: the chart's title, subtitle and caption, and the values it plots, or
the table's rows), so the AI can write about it from its numbers.
report_read( context, project, id = project$id, i18n = NULL, lang = "en", data = TRUE, max_rows = 25, max_cols = 8, max_chars = 2000 )report_read( context, project, id = project$id, i18n = NULL, lang = "en", data = TRUE, max_rows = 25, max_cols = 8, max_chars = 2000 )
context |
A report context ( |
project |
The report. |
id |
The report's id (by default its own). |
i18n |
A translator ( |
lang |
The language a report without one of its own is written in (it follows the app's). |
data |
Whether to draw the charts and tables for their data. |
max_rows, max_cols
|
The most rows and columns of each chart's or table's data. |
max_chars |
The most characters of each text. |
list(id, name, kind, lang, region, blocks). A slide deck's blocks are its slides' items (each with its
slide); a document's free page (canvas) lists its items' blocks in items.
Called once by an app package (usually in its .onLoad()); later calls replace only what they give.
report_register( themes = NULL, default_theme = NULL, cover = NULL, kinds = NULL, presets = NULL, indicator_name = NULL, fields = NULL, chart_id = NULL )report_register( themes = NULL, default_theme = NULL, cover = NULL, kinds = NULL, presets = NULL, indicator_name = NULL, fields = NULL, chart_id = NULL )
themes |
A named list of designs (see |
default_theme |
The id of the theme new reports start from. |
cover |
A list of cover fields that new reports start from (see |
kinds |
A function returning the kinds of chart and table, a named list of |
presets |
A function of |
indicator_name |
A function of |
fields |
A list of extra fields for |
chart_id |
A function of a chart's data and its ggplot returning the chart's id: the key its options are kept
under, for the screen and for reports (the same chart gets the same id in both). By default, |
Invisibly, NULL.
Puts the report's region in a block that asks for it (region = "@report"). A report without a region is a
national report: such a block is then drawn for the whole country (or asks for a region when it needs one).
report_resolve_block(block, project, regions = NULL)report_resolve_block(block, project, regions = NULL)
block |
A block. |
project |
The report (its |
regions |
Not used; kept for older callers. |
The block.
The size of a slide deck's slides, in inches
report_slide_size(design = NULL)report_slide_size(design = NULL)
design |
A design; its |
c(width, height) in inches.
Keeps a picture once in the dataset, from a data: URL (as the report builder uploads it) or from a web address
(downloaded now, so the report does not need the internet later). A picture larger than 4000 pixels is made smaller;
formats Word cannot show (WebP, for example) are converted to PNG.
report_store_asset(context, id, src)report_store_asset(context, id, src)
context |
A report context ( |
id |
The picture's id. |
src |
A |
A list: id, ratio (height / width) and url (a data: URL of the picture as stored), invisibly.
Reads the colours and fonts of an Office theme or template (PowerPoint .pptx / .potx, Word .docx / .dotx)
into a report theme, as report_themes() gives them: the accent is the theme's first accent colour, the text colour
its first dark colour, the chart palette its six accent colours, the heading and body fonts its heading and body
fonts. A Word file's styles give the heading colour (Heading 1's), the fonts and the text sizes when they set them,
and its page size, orientation and margins. A PowerPoint file's master gives the title colour and fonts, the slide
size and the background colour. The reading is Quire's (quire::quire_theme_from_file()).
report_theme_from_file(path, name = NULL)report_theme_from_file(path, name = NULL)
path |
The file. |
name |
The theme's name (by default the file's name without its extension). |
The same file can be given to the export as the design's template (its path): see export_deck() and
export_report().
A design (see report_default_design()) with theme ("custom_<hash of the file>"), name
(list(en, fr, pt)), and template_kind ("pptx" or "docx"); for a PowerPoint file also slide_size
("16:9" or "4:3", the nearer), background (the master's background colour, or NULL) and slide_designs:
list(title, content), the look of the file's title slide and of its other slides (either NULL when not found).
A slide design is list(background, decor, title, subtitle, body): background a colour or NULL; decor what
is drawn behind a slide's content, back first, each list(type = "image", file, x, y, w, h) (a logo: file is
the picture, copied out of the file into a temporary folder) or list(type = "rect", fill, fill_opacity, outline, x, y, w, h) (a band or bar), each also with from ("master", "layout" or "slide": where it was found);
title, subtitle, body the style of that text, list(x, y, w, h, fill, fill_opacity, color, font_size, bold, align, font), or NULL. Boxes are in inches from the slide's top-left corner; colours are "#rrggbb".
export_deck() draws a design's background and decor on its slides.
The ready-made looks a report can start from. Each is a complete design (see report_default_design()).
report_themes()report_themes()
A named list of designs; each also has name.
A translated string
report_translate(i18n, key, fallback = key)report_translate(i18n, key, fallback = key)
i18n |
An object with a |
key |
The key. |
fallback |
What to give when there is no translation (or no |
A string.
A standard report is written once, in the app's languages; report_in() gives it in one.
report_tx(en, fr = en, pt = en)report_tx(en, fr = en, pt = en)
en, fr, pt
|
The text in English, French and Portuguese (French and Portuguese default to the English). |
An object of class rb_tx.
Applies targeted changes, in order, to a report's blocks, and checks the result as a whole
(report_validate_project()). Only the blocks named change; the design, the cover and every other block stay as
they are. Each change is one of:
report_update_blocks( project, changes, kinds = .ds_report_kinds(), members = NULL )report_update_blocks( project, changes, kinds = .ds_report_kinds(), members = NULL )
project |
The report. |
changes |
A list of changes. |
kinds |
The kinds of chart and table (a named list of |
members |
Passed to |
list(blockId, <fields>): changes that block.
A heading, paragraph or note: text (plain text; a line break starts a new line, **bold** is bold), type
("heading", "paragraph" or "note"), level (a heading's, 1 to 6), align, space_before,
space_after (pt).
A chart or table: kind (another kind; the settings the new kind does not take are left out, those it needs
get its defaults), its settings indicator, admin_level, region, year, variant (as the kind allows;
NULL removes one), options (chart options, see cd_chart_options(); merged into the chart's own, NULL
removes one), size ("full", "half", "third"), title (NULL: the chart's own), caption (FALSE
hides the chart's caption).
A picture: caption, alt, size, width (percent of its column), align.
Any block of a document: pageBreakBefore (TRUE starts a new page before it, FALSE removes that).
list(afterBlockId, insert = <block>): a new heading, paragraph, note, page break, chart or table after that
block ("@start": at the start). Several inserted after the same block keep their order.
list(blockId, delete = TRUE): removes the block.
list(blockId, moveAfter = <id>): moves the block after another ("@start": to the start).
A slide deck's items can be changed, but not added, removed or moved.
list(project, changes): the changed report (without its sigs on changed charts: the builder signs them
again) and one sentence per change, saying what it did.
p <- list(name = "Notes", blocks = list(list(id = "b1", type = "paragraph", text = ""))) report_update_blocks(p, list(list(blockId = "b1", text = "Coverage rose."), list(afterBlockId = "b1", insert = list(type = "heading", text = "Next steps"))))$changesp <- list(name = "Notes", blocks = list(list(id = "b1", type = "paragraph", text = ""))) report_update_blocks(p, list(list(blockId = "b1", text = "Coverage rose."), list(afterBlockId = "b1", insert = list(type = "heading", text = "Next steps"))))$changes
Checks the shape of a report project (see export_report()) – one the AI built, say – before an app saves it:
each block's type, and for charts and tables their kind. A custom_chart block may carry its description in
spec or, as the AI bridge sends it, in options; either way it is checked with report_validate_spec() and kept
in spec.
report_validate_project(project, kinds = NULL, members = NULL)report_validate_project(project, kinds = NULL, members = NULL)
project |
|
kinds |
The report kinds charts and tables may use (names), or |
members |
Passed to |
The project, tidied (each block has an id). Stops with a message saying what is wrong.
report_validate_project(list(name = "Notes", blocks = list( list(type = "heading", text = "Summary"), list(type = "paragraph", text = "Coverage rose.") )))report_validate_project(list(name = "Notes", blocks = list( list(type = "heading", text = "Summary"), list(type = "paragraph", text = "Coverage rose.") )))
A custom chart (report kind "custom_chart") is described by data, never code: where its table comes from, a few
fixed transforms and a plot description. report_validate_spec() checks one before it is saved, and returns it
tidied (lists from JSON turned into vectors where a vector is meant).
report_validate_spec(spec, members = NULL)report_validate_spec(spec, members = NULL)
spec |
The description: |
members |
The names |
The spec, tidied. Stops with a message saying what is wrong.
report_validate_spec(list( title = "Coverage by region", data = list(member = "calculate_coverage", args = list(admin_level = "adminlevel_1")), transform = list(list(filter = list(year = 2023))), plot = list(geom = "col", x = "adminlevel_1", y = "value") ))report_validate_spec(list( title = "Coverage by region", data = list(member = "calculate_coverage", args = list(admin_level = "adminlevel_1")), transform = list(list(filter = list(year = 2023))), plot = list(geom = "col", x = "adminlevel_1", y = "value") ))
What every plot method calls with its options argument and its ...: options (an object, a list or NULL) plus any
chart-option field named in ... (unrelated arguments in ... are ignored). Named arguments in ... win.
resolve_chart_options(options = NULL, ...)resolve_chart_options(options = NULL, ...)
options |
A |
... |
Chart-option fields (or their older aliases). |
A cd_chart_options object.
Charts are written as SVG (vector: sharp at any size, on screen, printed or in the PDF Word makes) when the
svglite package is installed and file ends in .svg; otherwise as PNG at dpi.
save_report_chart(rendered, block, file, dpi = 200, design = NULL)save_report_chart(rendered, block, file, dpi = 200, design = NULL)
rendered |
The result of |
block |
The block (for its size). |
file |
Path of the file to write: |
dpi |
Resolution of a PNG. |
design |
The report's design (for the page size). |
file, invisibly.
Run code with the report's saved chart options in effect
with_report_chart_options(context, code, design = NULL)with_report_chart_options(context, code, design = NULL)
context |
A report context ( |
code |
Code that draws charts. |
design |
The report's design, whose fonts the charts use ( |
The value of code.