| Title: | Shared 'Shiny' Components for 'LLMR' Family Applications |
|---|---|
| Description: | Reusable 'Shiny' user interface and server components from which the graphical applications in the 'LLMR' package family are assembled. |
| Authors: | Ali Sanaei [aut, cre] |
| Maintainer: | Ali Sanaei <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.2 |
| Built: | 2026-07-22 22:48:55 UTC |
| Source: | https://github.com/asanaei/llmr.shiny |
Marks a result produced without a live model: a run_mode column set to
"demo", a demo_notice column, and the llmrshiny_demo_result class that
is_demo_result() tests and demo_banner_ui() announces. demo_runner()
applies it automatically; call it directly for demonstration results built
some other way.
annotate_demo_result(x)annotate_demo_result(x)
x |
A data frame of results. |
x with the two source columns and the demonstration class added.
annotate_demo_result(data.frame(response_text = "stub"))annotate_demo_result(data.frame(response_text = "stub"))
Data frames and matrices pass through (head-limited). For a list, name the component to display. Anything else becomes a one-column capture of its structure.
as_display_table(x, max_rows = 500L, component = NULL)as_display_table(x, max_rows = 500L, component = NULL)
x |
Any object. |
max_rows |
Row cap for the display. |
component |
For a list, the name of the component to display. |
A data frame.
Build an LLM config
build_llm_config(provider, model, ...)build_llm_config(provider, model, ...)
provider, model
|
Provider and model ids. |
... |
Passed to |
An LLMR::llm_config.
Build an execution function for a mode
build_runner(mode, responder = NULL)build_runner(mode, responder = NULL)
mode |
|
responder |
Optional demonstration responder (see |
A callable function that accepts a request data frame.
Column names of a data frame, for a mapping select input
column_names_for_mapping(data)column_names_for_mapping(data)
data |
A data frame. |
A character vector of column names.
LLMR's classed errors carry their category in the condition class
(llmr_api_auth_error, llmr_api_rate_limit_error, and so on); the class is
read first. A plain category field or attribute is honored as a fallback
for conditions built by other tools.
condition_category(e)condition_category(e)
e |
A condition. |
A length-1 character category (e.g. "auth", "rate_limit",
"param", "server", "unknown"), or NA.
A banner announcing a demonstration result
demo_banner_ui()demo_banner_ui()
A warning card.
Demo-result notice string
demo_notice()demo_notice()
The marker text stamped on every demo result.
Returns a function accepted by .runner arguments. It adds LLMR response
columns to a request data frame. The per-row response text is decided by
responder, a function (text) -> character. Results are marked as
demonstrations.
demo_runner( responder = NULL, text_cols = c("text", "unit", "document", "prompt", "input") ) ## S3 method for class 'llmrshiny_demo_result' print(x, ...)demo_runner( responder = NULL, text_cols = c("text", "unit", "document", "prompt", "input") ) ## S3 method for class 'llmrshiny_demo_result' print(x, ...)
responder |
A function mapping a single input text to a response string. Defaults to echoing a short stub. |
text_cols |
Candidate column names to read the input text from. |
x |
A demonstration result. |
... |
Passed to the next print method. |
A response function of class llmrshiny_demo_runner.
diagnostics() as a display tableRender an object's diagnostics() as a display table
diagnostics_table(x, ...)diagnostics_table(x, ...)
x |
A result object with an |
... |
Passed to |
A data frame, or NULL when no method applies.
Extract call/token counts from a result frame
extract_token_counts(x, fallback_calls = 0L)extract_token_counts(x, fallback_calls = 0L)
x |
A result data frame (or list containing one). |
fallback_calls |
Call count to use when |
A list with token totals and either calls, when explicit call
provenance is available, or result_rows.
Install-guidance card for a missing package
install_guidance_ui(package, title = package)install_guidance_ui(package, title = package)
package |
Package name. |
title |
Card title (defaults to the package name). |
A bslib::card with an installation command.
Is a result a demonstration result?
is_demo_result(x)is_demo_result(x)
x |
A result object. |
TRUE when the result has the demonstration class or source fields.
Never returns the key value; only whether one was found and in which variable.
key_state(provider)key_state(provider)
provider |
Provider id. |
A list: provider, display, env_vars, found, env_var.
A tile reporting key state (never the key value)
key_state_tile(state)key_state_tile(state)
state |
A |
A bslib value box or warning card.
A banner shown when a live run is blocked for want of a key
live_run_blocker_ui(state)live_run_blocker_ui(state)
state |
A |
A warning card.
text (and optionally labels)Map user columns to text (and optionally labels)
map_columns(data, text_col, label_col = NULL, keep_original = TRUE)map_columns(data, text_col, label_col = NULL, keep_original = TRUE)
data |
A data frame. |
text_col |
Name of the column to become |
label_col |
Optional name of the column to become |
keep_original |
Keep the original columns alongside the mapped ones.
A pre-existing |
A data frame with a text column (and labels when requested),
always with one row per input row.
Renders a compact overview of data as a multi-select table and returns the
selected row indices (relative to data) as a reactive. When data carries
the persona contract (see LLMR::llm_persona_overview()), the overview columns
are chosen automatically; otherwise the first few columns are shown.
persona_selector_server( id, data, overview = NULL, page_length = 8L, height = "260px" )persona_selector_server( id, data, overview = NULL, page_length = 8L, height = "260px" )
id |
Module id. |
data |
A persona data frame (or a |
overview |
Optional overview data frame, or a function |
page_length |
Rows per page in the table. Default |
height |
CSS height for the scrollable table body. Default |
A reactive returning an integer vector of selected row indices into
data (integer(0) when nothing is selected). When DT is not installed
the module renders nothing and the reactive is always integer(0),
matching the install guidance shown by persona_selector_ui().
Renders the selectable persona table. Pair with persona_selector_server().
The table's height is set by the height argument of
persona_selector_server(), which controls the scrollable body.
persona_selector_ui(id)persona_selector_ui(id)
id |
Module id. |
A Shiny UI element (a DT output).
Provider choices for a select input
provider_choices()provider_choices()
A named character vector (display -> provider).
Default model for a provider
provider_default_model(provider)provider_default_model(provider)
provider |
Provider id. |
The default model string, or "".
Display name for a provider
provider_display_name(provider)provider_display_name(provider)
provider |
Provider id. |
The display name, or the provider id.
Environment-variable names a provider's key may live in
provider_env_vars(provider)provider_env_vars(provider)
provider |
Provider id. |
A length-2 character vector c("<P>_API_KEY", "<P>_KEY").
Model defaults are optional because provider aliases can change between
package releases. Set the LLMR.shiny.default_models option to a named
character vector to supply local defaults.
provider_registry( default_models = getOption("LLMR.shiny.default_models", character()) )provider_registry( default_models = getOption("LLMR.shiny.default_models", character()) )
default_models |
A named character vector of provider model defaults. |
A data frame of provider, display, and default_model.
Read a CSV from a path
read_csv_path(path)read_csv_path(path)
path |
File path. |
A data frame.
Read an uploaded CSV (a Shiny fileInput value)
read_csv_upload(file)read_csv_upload(file)
file |
A |
A data frame.
report() prose, falling back to print outputRender an object's report() prose, falling back to print output
report_text(x, ...)report_text(x, ...)
x |
A result object with an |
... |
Passed to |
A character scalar of report text.
Evaluates expr; on error returns a list with ok = FALSE and a ready-made
ui banner (auth-aware) instead of stopping. On success returns
ok = TRUE and the value.
safe_llmr_call(expr, provider = NULL)safe_llmr_call(expr, provider = NULL)
expr |
An expression to evaluate. |
provider |
Optional provider id, for an auth banner. |
list(ok, value, error, ui).
Call once at the top of a GUI's server with the top-level input, output,
session. It keeps the model field in sync with the provider, renders the
key and usage tiles, tracks usage, and returns a list of reactives and
mutators (provider, model, mode, key, can_run, set_plan,
add_usage) for the per-package modules to consume.
shell_context(input, output, session)shell_context(input, output, session)
input, output, session
|
The top-level Shiny server arguments. |
A shared-context list.
The standard GUI sidebar: provider, model, mode, key tile, usage tile
shell_sidebar(id = NULL, default_provider = "groq")shell_sidebar(id = NULL, default_provider = "groq")
id |
The module namespace (or |
default_provider |
Provider selected initially. |
A bslib::sidebar.
Add realized usage to a usage record
usage_add(state, tokens)usage_add(state, tokens)
state |
A usage record. |
tokens |
A token-count list (see |
The updated usage record.
An empty usage record
usage_empty()usage_empty()
A list with zeroed counters.
Record a planned run on a usage record
usage_set_plan(state, calls, label = "Next run")usage_set_plan(state, calls, label = "Next run")
state |
A usage record. |
calls |
Number of calls the next run will make. |
label |
A short label for the planned run. |
The updated usage record.
A value box reporting session usage
usage_tile(state)usage_tile(state)
state |
A usage record. |
A bslib::value_box.
Validate a column mapping
validate_column_mapping(data, text_col, label_col = NULL)validate_column_mapping(data, text_col, label_col = NULL)
data |
A data frame. |
text_col |
Required text column name. |
label_col |
Optional label column name. |
TRUE, or an error.