| Title: | Shared 'Shiny' Substrate for 'LLMR' Family GUIs |
|---|---|
| Description: | Provides the shared shell that 'LLMR'-family graphical interfaces are built on. It includes provider and model selection, environment-variable-based API-key handling, demo and live runners, session cost accounting, error banners, comma-separated-value upload and column mapping, and display helpers for the shared diagnostics() and report() generics. Graphical interfaces for the method packages import these helpers rather than each reimplementing them, so a fix here is available to every interface that depends on it. |
| Authors: | Ali Sanaei [aut, cre] |
| Maintainer: | Ali Sanaei <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.1 |
| Built: | 2026-07-21 10:48:13 UTC |
| Source: | https://github.com/cran/LLMR.shiny |
Mark a result as a demo result
annotate_demo_result(x)annotate_demo_result(x)
x |
A result object. |
x with a llmrshiny_demo attribute.
Data frames and matrices pass through (head-limited); a list yields its first data frame; anything else becomes a one-column capture of its structure.
as_display_table(x, max_rows = 500L)as_display_table(x, max_rows = 500L)
x |
Any object. |
max_rows |
Row cap for the display. |
A data frame.
Build an LLM config, falling back to a plain list without LLMR
build_llm_config(provider, model, ...)build_llm_config(provider, model, ...)
provider, model
|
Provider and model ids. |
... |
Passed to |
An llm_config when LLMR is available, else a tagged list.
Build a runner for a mode
build_runner(mode, responder = NULL)build_runner(mode, responder = NULL)
mode |
|
responder |
Optional demo responder (see |
A demo runner for "demo", or NULL for "live" (use the package
default downstream).
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.
Add realized usage to a cost record
cost_add_usage(state, tokens)cost_add_usage(state, tokens)
state |
A cost record. |
tokens |
A token-count list (see |
The updated cost record.
An empty cost-accounting record
cost_empty()cost_empty()
A list with zeroed counters.
Record a planned run on a cost record
cost_set_plan(state, calls, label = "Next run")cost_set_plan(state, calls, label = "Next run")
state |
A cost record. |
calls |
Number of calls the next run will make. |
label |
A short label for the planned run. |
The updated cost record.
A value box reporting session usage
cost_tile(state)cost_tile(state)
state |
A cost record. |
A bslib::value_box.
A banner announcing a demo 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 with the .runner contract (experiments, ...) that adds
LLMR-shaped response columns. The per-row response text is decided by
responder, a function (text) -> character. Results are marked as demo.
demo_runner( responder = NULL, text_cols = c("text", "unit", "document", "prompt", "input") )demo_runner( responder = NULL, text_cols = c("text", "unit", "document", "prompt", "input") )
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. |
A runner 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 assume when none can be read. |
A list list(calls, sent, received, total).
GitHub remote for an LLMR-family package
github_remote_for(package)github_remote_for(package)
package |
Package name. |
A "owner/repo" string for remotes::install_github().
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 install_github() snippet.
Is a caught condition an auth error?
is_auth_error(e)is_auth_error(e)
e |
A condition. |
TRUE when the condition is an LLMR llmr_api_auth_error or its
category otherwise resolves to "auth".
Is a result a demo result?
is_demo_result(x)is_demo_result(x)
x |
A result object. |
TRUE when marked by annotate_demo_result().
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.
An auth failure becomes a key-state banner naming the environment variables to set; any other error shows its message verbatim. Neither crashes the app.
llmr_error_banner(e, provider = NULL)llmr_error_banner(e, provider = NULL)
e |
A caught condition. |
provider |
Optional provider id, for the key banner. |
A bslib::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.
Returns x unless it is NULL or empty, in which case y.
x %||% yx %||% y
x, y
|
Values; |
x if non-NULL and length > 0, otherwise y.
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).
Is a package installed?
pkg_available(package)pkg_available(package)
package |
Package name. |
TRUE if the package can be loaded.
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").
Provider registry
provider_registry()provider_registry()
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 cost 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, cost 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.
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.