| Title: | A Lightweight Editable Matrix Input for Shiny |
|---|---|
| Description: | An editable matrix (grid of text inputs) as a Shiny input, with a dependency-free vanilla-JavaScript client binding. Create a matrix input with 'matrixInput()' and update it from the server with 'updateMatrixInput()'. A trimmed, Vue-free reimplementation of the subset of the 'shinyMatrix' widget needed by typical apps: a static header row of column names plus editable cells, with server-driven resets. |
| Authors: | Yihui Xie [aut, cre, cph] (ORCID: <https://orcid.org/0000-0003-0645-5666>, URL: https://yihui.org) |
| Maintainer: | Yihui Xie <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.2 |
| Built: | 2026-10-12 14:56:42 UTC |
| Source: | https://github.com/yihui/shinyMat |
Create a grid of text inputs that reports its value to Shiny as a matrix. The client binding is dependency-free vanilla JavaScript; its assets are attached automatically wherever 'matrixInput()' is used, so no 'addResourcePath()' setup is required.
matrixInput( inputId, label = NULL, value = matrix("", 1, 1), inputClass = "", rows = list(), cols = list(), class = "character" )matrixInput( inputId, label = NULL, value = matrix("", 1, 1), inputClass = "", rows = list(), cols = list(), class = "character" )
inputId |
The input slot that will be used to access the value. |
label |
Display label for the control, or 'NULL' for no label. |
value |
The initial value, a [matrix]. Row and column names, if present, are used as the row/column headers. |
inputClass |
Extra CSS class(es) to add to the input container. |
rows, cols
|
A list of options for the rows/columns. Recognized fields: 'names' (whether to show headers; columns only by default) and 'editableNames', 'extend' (accepted for compatibility but not acted on by this lightweight client). |
class |
The storage mode of the matrix, ''character'‘ or '’numeric''. Numeric inputs reject non-numeric cell entries on the client. |
The widget renders an optional static row of column headers plus one editable cell per matrix entry. Adding or removing rows and columns is expected to be driven from the server via [updateMatrixInput()]; the client does not resize the matrix itself.
A Shiny input element.
[updateMatrixInput()] to change the value from the server.
if (interactive()) { library(shiny) shinyApp( ui = fluidPage( matrixInput('m', 'A 2x2 numeric matrix', value = matrix(1:4, 2, dimnames = list(NULL, c('a', 'b'))), class = 'numeric'), verbatimTextOutput('out') ), server = function(input, output, session) { output$out = renderPrint(input$m) } ) }if (interactive()) { library(shiny) shinyApp( ui = fluidPage( matrixInput('m', 'A 2x2 numeric matrix', value = matrix(1:4, 2, dimnames = list(NULL, c('a', 'b'))), class = 'numeric'), verbatimTextOutput('out') ), server = function(input, output, session) { output$out = renderPrint(input$m) } ) }
Replace the full matrix shown by a [matrixInput()] from the server, e.g. to add or remove rows/columns or reset the grid. The client re-renders and reports the new value back to Shiny.
updateMatrixInput(session, inputId, value)updateMatrixInput(session, inputId, value)
session |
The 'session' object passed to the Shiny server function. |
inputId |
The id of the input object. |
value |
The new value, a [matrix]. Its row/column names become the row/column headers. |
Called for its side effect; returns 'NULL' invisibly.