| Title: | A Word-Like Report Builder for Shiny |
|---|---|
| Description: | Quire's report builder in a Shiny app: a Word-like editor of documents and slide decks that writes Word, PowerPoint and PDF files itself, in the browser. The app is its host: it says what charts and tables it can draw and draws them (with 'ggplot2' or any other way), and keeps the reports; everything else, the editing, the page layout, the files and an AI's reading and editing of reports, is done by the builder. |
| 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 <[email protected]> |
| License: | file LICENSE |
| Version: | 0.2.17 |
| Built: | 2026-09-30 01:32:23 UTC |
| Source: | https://github.com/damurka/quire |
Whether this computer can print the builder's printable page
quire_can_print()quire_can_print()
TRUE when the chromote package and a Chromium browser (Chrome, Edge, Chromium) are there: then
quire_html_pdf() and quire_print_pages() work.
The one description of the chart options (from Quire's contract, chart-options.json): each option's type and, for
a choice, its values; and the chart panel that edits them – its elements, its settings with their labels in each
language, and its texts. The report builder has the same file, so a host that draws charts validates and lists the
options from here instead of keeping its own copy.
quire_chart_options()quire_chart_options()
A list: options (by name: type, and choices for a choice), tabs (the panel's elements: key,
label, icon, and show, the option that shows or hides it), fields (its settings: key, tab, group,
label, type, and choices, keywords, step, min, max when they have them) and texts (the panel's own
words). Labels are lists by language (en, fr, pt).
Microsoft Word or PowerPoint (Windows), else LibreOffice. With one of them the PDF has exactly the file's pages.
quire_converter(kind = c("document", "deck"))quire_converter(kind = c("document", "deck"))
kind |
|
"word" or "powerpoint", "libreoffice", or NULL when none is installed.
The report builder's browser bundle (quire.js), its styles and fonts, as an HTML dependency. quire_ui()
includes it; call it yourself only to load the builder in a page of your own.
quire_dependency()quire_dependency()
An htmltools::htmlDependency().
Calls the host's function for a call from the builder and makes its answer. quire_server() does this for
every message; it is exported for tests and for hosts that carry the messages themselves.
quire_dispatch(host, message)quire_dispatch(host, message)
host |
A host made with |
message |
A message from the builder, as a list: |
The result to send back (a list: kind = "result", id, ok, and result or error), or NULL
when the message is not a call.
A block the host could not draw
quire_error(message)quire_error(message)
message |
Why, for the reader. |
An error drawing, shown in the block's place.
The same writers as the builder's downloads (Quire's), run in R through 'V8', with no browser: a report written
here is the file the builder would have made. The host draws the report's charts and tables as it does for the
builder (its render), gives its fields and pictures; the pictures are turned and cropped with 'magick', SVG
drawings made pictures with 'rsvg'.
quire_export( project, host, file, format = c("docx", "pptx", "pdf", "html"), lang = NULL, fields = NULL, pdf = NULL )quire_export( project, host, file, format = c("docx", "pptx", "pdf", "html"), lang = NULL, fields = NULL, pdf = NULL )
project |
The report (a list, as saved), or its id (the host's |
host |
The host, made with |
file |
Where to write it. |
format |
|
lang |
The language of the report's texts when it has none of its own. |
fields |
The fields' values; by default the host's |
pdf |
For a PDF: |
file, invisibly.
Makes the host's listReports, getReport, saveReport, deleteReport, assetGet and assetSet, keeping
each report as a JSON file in dir (its pictures in dir/assets), as the builder sends it. Give them to
quire_host() with do.call() or ....
quire_file_store(dir)quire_file_store(dir)
dir |
The folder (made if it is not there). |
A named list of functions.
The host answers the builder's few questions. Only kinds and render are needed; each other one adds a
feature (the text fields, report templates, keeping reports in the app, pictures, extra ribbon groups...).
Without listReports/getReport/saveReport the reports are kept in the reader's browser.
quire_host( kinds, render, fields = NULL, fieldCatalog = NULL, presets = NULL, preset = NULL, themes = NULL, years = NULL, regions = NULL, flag = NULL, listReports = NULL, getReport = NULL, saveReport = NULL, deleteReport = NULL, assetGet = NULL, assetSet = NULL, saveFile = NULL, extensions = NULL, action = NULL, ... )quire_host( kinds, render, fields = NULL, fieldCatalog = NULL, presets = NULL, preset = NULL, themes = NULL, years = NULL, regions = NULL, flag = NULL, listReports = NULL, getReport = NULL, saveReport = NULL, deleteReport = NULL, assetGet = NULL, assetSet = NULL, saveFile = NULL, extensions = NULL, action = NULL, ... )
kinds |
|
render |
|
fields |
|
fieldCatalog |
|
presets, preset
|
|
themes |
|
years, regions
|
|
flag |
|
listReports, getReport, saveReport, deleteReport
|
Keeping reports in the app: |
assetGet, assetSet
|
Pictures kept once in the app: |
saveFile |
|
extensions |
|
action |
|
... |
Any other method of the host protocol, by name. |
A host, to give quire_server().
pdf = function(html, name) makes a PDF of the printable page (html), returned as
list(type = "application/pdf", data = <base 64>); pages = function(html, name) makes its pages as they are
printed, for Print Preview: list(pages = <list of image data URLs>, converter = <what printed them>). A host
that gives neither gets Quire's own (quire_html_pdf(), quire_print_pages()), which print with Chrome, Edge
or Chromium when the computer has one (and chromote, pdftools); without them the builder prints in the
reader's browser.
Prints the page (the HTML the builder makes a PDF from) with a Chromium browser, its page size, margins, headers and
footers as the page sets them (CSS @page). Needs the chromote package and Chrome, Edge or Chromium.
quire_html_pdf(html, pdf)quire_html_pdf(html, pdf)
html |
The printable page: its HTML, or an |
pdf |
The PDF to write. |
pdf, invisibly.
A kind of chart or table the app draws
quire_kind( kind, type = c("chart", "table"), label, group = "charts", groupLabel = group, ... )quire_kind( kind, type = c("chart", "table"), label, group = "charts", groupLabel = group, ... )
kind |
Its id. |
type |
|
label |
Its name, a string or a list of names by language ( |
group, groupLabel
|
The group it is listed in (its id and name). |
... |
Anything else a kind may say: |
A kind, a list.
Draws a plot at the size the builder asks for. With 'svglite' installed the drawing is an SVG (sharp at any zoom, and made a picture in the files by the builder); without it, a PNG.
quire_plot(plot, request, chart = NULL, dpi = 144)quire_plot(plot, request, chart = NULL, dpi = 144)
plot |
A 'ggplot2' plot, or a function that draws on the current device. |
request |
The render request (its |
chart |
Optionally, the chart as data ( |
dpi |
The PNG's dots per inch (without 'svglite'). |
A drawing, to return from the host's render.
Prints the page to PDF (quire_html_pdf()) and renders each page as a picture: what the builder's Print Preview
shows. Needs the pdftools package too.
quire_print_pages(html, dpi = 80)quire_print_pages(html, dpi = 80)
html |
The printable page: its HTML, or an |
dpi |
Resolution of the pictures. |
list(pages = <list of PNG data URLs>, converter = "browser").
Answers the builder's calls with the host's functions, in the module id.
quire_server(id, host, on_event = NULL)quire_server(id, host, on_event = NULL)
id |
The module's id (as given to |
host |
The host, made with |
on_event |
Optionally, |
A list of functions to tell the builder things: send(name, data) sends an event ("data.changed"
when the app's data changed, so the charts are drawn again; "report.changed" with list(project = ...) when a
report changed elsewhere; "reports.changed" when the list of reports did; "report.open" with list(id = ...)
to open one; "lang" with list(lang = ...)), dataChanged() as a shortcut.
The builder draws the table itself, in the report's style and its Table Design; the host gives its cells.
quire_table(data, footer = NULL, widths = NULL, text = NULL)quire_table(data, footer = NULL, widths = NULL, text = NULL)
data |
A data frame: its column names are the header, its rows the table's rows (numbers kept as values,
shown as |
footer |
A note under the table (its source), or |
widths |
The columns' shares of the width (summing to 1), or |
text |
Optionally, a data frame of the same shape with the cells' texts. |
A table, to return from the host's render.
Reads the colours and fonts of an Office theme or template (PowerPoint .pptx / .potx, Word .docx / .dotx)
into the fields of a report design, with the report builder's own reader (Quire's, run here through 'V8'), so a
theme read in R is the one the builder reads: 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, and its slides their designs: the logos, bands and title boxes they carry.
quire_theme_from_file(path, name = NULL, default_accent = NULL)quire_theme_from_file(path, name = NULL, default_accent = NULL)
path |
The file. |
name |
The theme's name (by default the file's name without its extension). |
default_accent |
The accent when the file's theme has none. |
A list of the design fields the file sets: template_kind ("pptx" or "docx"), theme, name
(list(en, fr, pt)), accent, heading_color, text_color, muted_color, note_fill, note_border,
apply_palette, and when the file has them heading_font, body_font, palette. For a PowerPoint file also
background (the master's background colour, or NULL), slide_size ("16:9" or "4:3") and slide_designs
(list(title, content), each NULL or list(background, decor, title, subtitle, body); a picture of decor has
src, a data URL, and name). For a Word file the text sizes it sets (body_size, h1_size, h2_size,
title_size, caption_size), orientation, size and margins.
A Word or PowerPoint file as a PDF
quire_to_pdf(file, pdf, converter = NULL)quire_to_pdf(file, pdf, converter = NULL)
file |
The Word ( |
pdf |
The PDF to write. |
converter |
|
pdf, invisibly, with attribute converter.
The report builder in a Shiny app's UI
quire_ui(id, lang = "en", theme = NULL, ...)quire_ui(id, lang = "en", theme = NULL, ...)
id |
The module's id (as given to |
lang |
The interface's language ( |
theme |
The interface's look: a list of design tokens ( |
... |
Anything else the builder takes ( |
The UI, to put in the app's page.
Microsoft Word opens the file, fills in its contents page and page numbers, embeds its fonts and saves it; with
pdf, it also saves the PDF, so the Word file and the PDF are the same document. Windows, with Word installed.
quire_word_finish(docx, pdf = NULL)quire_word_finish(docx, pdf = NULL)
docx |
The Word file. |
pdf |
The PDF to write too, or |
TRUE, invisibly; an error when Word could not.