Title: | 'ShinyItemAnalysis' Modules Development Toolkit |
Version: | 0.1.3 |
Description: | A comprehensive suite of functions designed for constructing and managing 'ShinyItemAnalysis' modules, supplemented with detailed guides, ready-to-use templates, linters, and tests. This package allows developers to seamlessly create and integrate one or more modules into their existing packages or to start a new module project from scratch. |
License: | GPL (≥ 3) |
URL: | https://applstat.github.io/SIAtools/ |
Depends: | R (≥ 3.6.0) |
Imports: | cli, desc, fs, magrittr, purrr, rlang, shiny, usethis, yaml |
Suggests: | glue, knitr, lintr, pkgload, rmarkdown, roxygen2, rstudioapi, spelling, testthat (≥ 3.0.0), tibble, tidyr, withr, xml2 |
VignetteBuilder: | knitr |
Config/testthat/edition: | 3 |
Encoding: | UTF-8 |
Language: | en-US |
RoxygenNote: | 7.3.2 |
NeedsCompilation: | no |
Packaged: | 2025-06-09 15:00:25 UTC; netik |
Author: | Jan Netik |
Maintainer: | Jan Netik <netik@cs.cas.cz> |
Repository: | CRAN |
Date/Publication: | 2025-06-09 15:20:02 UTC |
SIAtools: 'ShinyItemAnalysis' Modules Development Toolkit
Description
A comprehensive suite of functions designed for constructing and managing 'ShinyItemAnalysis' modules, supplemented with detailed guides, ready-to-use templates, linters, and tests. This package allows developers to seamlessly create and integrate one or more modules into their existing packages or to start a new module project from scratch.
Author(s)
Maintainer: Jan Netik netik@cs.cas.cz (ORCID)
Authors:
Patricia Martinkova martinkova@cs.cas.cz (ORCID)
See Also
Useful links:
Add a new SIA module to your package
Description
This is the workhorse of {SIAtools}
package. The function checks if the
package is properly configured for SIA modules and provides immediate fixes
as needed. add_module()
automatically puts a correct entry in SIA Modules
Manifest of your package (which is created if not already present), and
prepares .R
file with the code template. Both files are automatically
opened for you by default.
Usage
add_module(
name = "new_module",
title = NULL,
category = NULL,
open = TRUE,
prefix = "sm_",
proj = curr_proj()
)
Arguments
name |
character, a name for the new SIA module. |
title |
character, new module's title. You can leave the default
|
category |
character, new module's category. The category dictates the
tab within the |
open |
Whether to open the manifest and module's source for interactive
editing. Defaults to |
prefix |
character, a prefix to denote SIA module. It's highly
recommended to stick with the default |
proj |
character, a path to the project. Defaults to current project. |
Value
No return value. Called for the side effects.
See Also
Other module management functions:
get_modules()
,
preview_module()
,
remove_module()
Examples
## Not run:
# add the module called "test" and edit the details later on in the YAML
add_module("test")
# specify the title and category at creation time
add_module("test", title = "Test module", category = "Validity")
## End(Not run)
Check if a package is identified as containing SIA modules
Description
Check if a package is identified as containing SIA modules
Usage
check_description(proj = curr_proj())
Arguments
proj |
character, a path to the project. Defaults to current project. |
Value
Side effects.
Create a new RStudio project prepared for SIA modules
Description
The function is designed to be used primarily by RStudio "New Project Wizard". Create a new project by navigating through File > New Project > New Directory > ShinyItemAnalysis Module Project. See RStudio User Guide for the details.
Usage
create_module_project(path, ..., open = TRUE)
Arguments
path |
character, a path to the new module. Use |
... |
used by RStudio only |
open |
logical, whether to open the project in new RStudio session
after creation. Defaults to |
Value
No return value. Called for the side effect.
Examples
if (interactive()) {
# create a new SIA module project in the parent of your working directory
create_module_project("../my_new_module")
}
Get a current project path
Description
This is a thin wrapper around usethis::proj_get()
that silences any messages.
Usage
curr_proj()
Value
The path to the current project.
See Also
Other helpers:
default_shiny_io_functions
,
edit_rstudio_shortcuts()
,
list_categories()
,
open_sm_manifest()
,
print.sm_manifest()
,
sia_head_tag()
Examples
## Not run:
curr_proj()
## End(Not run)
Default {shiny}
input/output UI functions consulted by
module_namespace_linter()
Description
A character vector of function names whose calls are inspected for ns()
omission. Name of each element denotes the original package. Please refer to
module_namespace_linter()
for more details.
Usage
default_shiny_io_functions
Format
An object of class character
of length 25.
Details
Following functions are covered:
-
shiny::actionButton
-
shiny::actionLink
-
shiny::checkboxGroupInput
-
shiny::checkboxInput
-
shiny::dateInput
-
shiny::dateRangeInput
-
shiny::fileInput
-
shiny::numericInput
-
shiny::passwordInput
-
shiny::radioButtons
-
shiny::selectInput
-
shiny::sliderInput
-
shiny::textAreaInput
-
shiny::textInput
-
shiny::varSelectInput
-
shiny::dataTableOutput
-
shiny::tableOutput
-
shiny::uiOutput
-
shiny::htmlOutput
-
shiny::verbatimTextOutput
-
shiny::imageOutput
-
shiny::textOutput
-
shiny::plotOutput
-
plotly::plotlyOutput
-
DT::DTOutput
See Also
Other helpers:
curr_proj()
,
edit_rstudio_shortcuts()
,
list_categories()
,
open_sm_manifest()
,
print.sm_manifest()
,
sia_head_tag()
Show RStudio Keyboard Shortcuts
Description
Shows a popup window with RStudio keyboard shortcuts. Applicable only in
RStudio and in interactive R
session.
Usage
edit_rstudio_shortcuts()
Details
You can quickly reach out solicited addin function by typing it in the
Filter...
box in the very top of the window. Then double click at the blank
space just next to the addin function name and press down desired key or key
combination. Apply the changes and from now on, just call the addin function
with one keystroke. For more details, navigate to RStudio documentation.
Value
No return value. Called for side effect.
See Also
Other helpers:
curr_proj()
,
default_shiny_io_functions
,
list_categories()
,
open_sm_manifest()
,
print.sm_manifest()
,
sia_head_tag()
Examples
if (interactive()) {
edit_rstudio_shortcuts()
}
Get the SIA Modules Manifest for the currently developed package
Description
Returns a list with all modules for the current package as described in its
SIA Modules Manifest, which resides at /inst/sia/modules.yml
and is
generated with add_module()
calls. Can be formatted as a tibble
using the
respective print method.
Usage
get_modules(proj = curr_proj())
Arguments
proj |
character, a path to the project. Defaults to current project. |
Value
A SIA Modules Manifest of class sm_manifest
. Inherits from a
list
.
See Also
Other module management functions:
add_module()
,
preview_module()
,
remove_module()
Examples
## Not run:
get_modules()
## End(Not run)
Check the {shiny}
module UI functions for ns()
omission
Description
This is a simple wrapper of lintr::lint_package()
call using only the
module_namespace_linter()
from {SIAtools}
. See the
linter documentation for more details.
Usage
lint_ns(path = curr_proj(), ...)
Arguments
path |
character, path to the package root directory. Default is the current project’s directory. |
... |
Arguments passed on to
|
Value
An object of class c("lints", "list"), each element of which is a "list" object.
See Also
Other linter-related functions:
module_namespace_linter()
Examples
## Not run:
lint_ns()
## End(Not run)
List the available SIA module categories
Description
Lists all available categories a SIA module can be placed in. SIA app will place the module with illegal category under "Modules".
Usage
list_categories()
Value
A character vector.
See Also
Other helpers:
curr_proj()
,
default_shiny_io_functions
,
edit_rstudio_shortcuts()
,
open_sm_manifest()
,
print.sm_manifest()
,
sia_head_tag()
Examples
list_categories()
Require usage of ns()
in inputId
and outputId
arguments of UI functions
in {shiny}
modules
Description
A custom linter to be used by {lintr}
package. Checks the functions in a
module's UI part for any missing ns()
calls. These are often omitted when
working with the plain {shiny}
or SIA modules. More details follows below.
Usage
module_namespace_linter(
io_funs = default_shiny_io_functions,
io_args = c("inputId", "outputId"),
ns_funs = c("ns", "NS")
)
Arguments
io_funs |
character, |
io_args |
character, arguments of UI functions to check. |
ns_funs |
character, function names that are considered valid in order
to "namespace" inputs' or outputs' IDs. Defaults to both |
Details
How to use this linter
The easiest way is to call lint_ns()
which is essentially a wrapper around:
lintr::lint_package(linters = module_namespace_linter())
Both calls use our linter for the whole package. However, note that only
module_namespace_linter
is considered. Using this custom linter with the
native ones is somewhat complicated, but not impossible. To the best of our
knowledge, the only place where the {lintr}
documentation mentions the
actual usage of external linters, is in
linters_with_tags() help page. According to that,
you can pass the following call to linters
argument in any supported
lintr::lint_*
function:
lintr::linters_with_tags( tags = NULL, packages = c("lintr", "SIAtools") )
That should select all linters available in both packages.
It is also possible to set up a configuration file that enables you to
shorten calls to {lintr}
functions, use RStudio Addins to lint an active
file, or even apply linters during continuous integration workflows, e.g., in
GitHub Actions or in Travis. To opt for that, create .lintr
file at your
package's root and fill in the following line:
linters: linters_with_tags(tags = NULL, packages = "SIAtools")
Then, you can use the provided addins or call lintr::lint_package()
to get
your modules checked.
What the linter does
By default, the linter looks for any inputId
or outputId
arguments of
{shiny}
's UI functions (such as numericInput or
plotOutput, respectively), and tests if the values
assigned to the arguments are all "namespaced", i.e., wrapped in ns()
function. This is crucial for inputs and outputs in the UI portion of a
module to match their counterparts in the server logic chunk.
Only {shiny}
UI calls that are inside of a tagList in a
function ("lambda" shorthand, \( )
, applies as well) are inspected. This is
because we don't want to cause false alarms for any "ordinary" {shiny}
apps
that aren't modules. All UI portions of modules are usually defined as
functions, and all input/output UI functions are inside a
tagList, so we opted for the this strategy to minimalize
false positive matches outside {shiny}
modules.
We look for any inputId
or outputId
arguments that are named as such. On
top of that, the ns()
omission is detected even if you call the function
without named arguments that would be evaluated as input or output IDs.
However, if you use partial matching (numericInput(inp = "input")
), the
actual input won't get linted, even though it should, as it is eventually
evaluated as inputId
. The same applies for arguments defined outside the
call and passed as a variable, e.g., inp <- "input"; numericInput(inputId = inp)
. That is tricky to catch in a static code analysis, which is employed
in this linter.
Value
A linter
closure. To be used by {lintr}
only. See the first
example below.
See Also
linters for a complete list of linters available in lintr.
Other linter-related functions:
lint_ns()
Examples
# will produce lints
lintr::lint(
text =
"module_ui <- function(id, imports, ...) {
tagList(
numericInput(inputId = \"input_id_without_ns\", ...)
)
}",
linter = module_namespace_linter()
)
# is OK
lintr::lint(
text =
"module_ui <- function(id, imports, ...) {
tagList(
numericInput(inputId = ns(\"input_id_with_ns\"), ...)
)
}",
linter = module_namespace_linter()
)
Open SIA Modules Manifest for Editing
Description
Open SIA Modules Manifest for Editing
Usage
open_sm_manifest(proj = curr_proj())
Arguments
proj |
character, a path to the project. Defaults to current project. |
Value
character, a path to SIA Module Manifest (invisibly).
See Also
Other helpers:
curr_proj()
,
default_shiny_io_functions
,
edit_rstudio_shortcuts()
,
list_categories()
,
print.sm_manifest()
,
sia_head_tag()
Examples
## Not run:
open_sm_manifest()
## End(Not run)
Preview a module
Description
Previews a SIA module in a standalone development environment. See the details below.
Usage
preview_module(
module_id = NULL,
ui_imports = NULL,
server_imports = NULL,
ui_elements = sia_head_tag(),
save_and_document = TRUE,
load = TRUE,
proj = curr_proj(),
...
)
Arguments
module_id |
character, name of the module to preview (including the
prefix). If |
ui_imports |
list, UI objects exported from the |
server_imports |
list, reactive objects exported from the
|
ui_elements |
elements to include in |
save_and_document |
logical, whether to save all unsaved files (only available in RStudio)
and document the package. Defaults to |
load |
logical, whether to load your package
before running the module preview. Defaults to |
proj |
character, a path to the project. Defaults to current project. |
... |
Arguments passed on to
|
Details
The function takes module's function bindings and puts (or evaluates) them
inside a bare bone shiny::shinyApp()
. By default, a customized head tag is
injected in order to mimic the "environment" of full {ShinyItemAnalysis}
app. See sia_head_tag()
for more details. Besides, a onSessionEnded
hook
is set to call shiny::stopApp()
after the client disconnects, so the
"process" is automatically quit after you close the preview in your browser
or RStudio viewer.
In order to use the function bindings, preview_module()
attempts to
load your package without the actual installation by
default.
Note that you have to install the package as usual for
{ShinyItemAnalysis}
to detect your modules.
Using objects from the {ShinyItemAnalysis}
app
Note that this "emulated" preview environment is really meant to test the
basic UI layout and functionality and is not able to receive any object from
{ShinyItemAnalysis}
app. However, you can pass any object like
{ShinyItemAnalysis}
does to server_imports
argument manually. For further
details and examples, please refer to vignette("imports", "SIAtools")
vignette.
Value
Shiny app object of class shiny.appobj
.
See Also
Other module management functions:
add_module()
,
get_modules()
,
remove_module()
Examples
if (interactive()) {
preview_module()
}
Print a SIA Modules Manifest
Description
Prints out the SIA Modules Manifest obtained through get_modules()
. By
default, a plain YAML content is returned, but you can also get a formatted
output in a tibble
, which is suitable for packages with large number of SIA
modules.
Usage
## S3 method for class 'sm_manifest'
print(x, ..., as_tibble = FALSE)
Arguments
x |
sm_manifest object, i.e., an output of |
... |
Not used at the moment. |
as_tibble |
logical, print the manifest as a |
Value
Called for side effects by default. Returns a tibble
if as_tibble
argument is set to TRUE
.
See Also
Other helpers:
curr_proj()
,
default_shiny_io_functions
,
edit_rstudio_shortcuts()
,
list_categories()
,
open_sm_manifest()
,
sia_head_tag()
Remove a module
Description
Removes the given module from the SIA Module Manifest and deletes the
respective .R
file.
Usage
remove_module(module_id = NULL, proj = curr_proj())
Arguments
module_id |
character, name of the module to remove (including the
prefix). If |
proj |
character, a path to the project. Defaults to current project. |
Value
No return value. Called for the side effect.
See Also
Other module management functions:
add_module()
,
get_modules()
,
preview_module()
Examples
## Not run:
remove_module()
## End(Not run)
Save all opened files and document the package in development
Description
Save all opened files and document the package in development
Usage
save_and_document_fun(proj = curr_proj())
Arguments
proj |
character, a path to the project. Defaults to current project. |
Value
No return value. Called for side effects.
Core HTML head tag from ShinyItemAnalysis
Description
This function is intended to be used for SIA module preview only, which is
done by default in preview_module()
. It provides a HTML head tag with a
math rendering facility provided by the
\KaTeX
library, and some CSS rules to
format tables. If printed in the console, expect nothing to be shown.
Usage
sia_head_tag()
Value
HTML head tag of class shiny.tag
.
See Also
Other helpers:
curr_proj()
,
default_shiny_io_functions
,
edit_rstudio_shortcuts()
,
list_categories()
,
open_sm_manifest()
,
print.sm_manifest()
List SIA module packages available on the official repository
Description
List SIA module packages available on the official repository
Usage
sm_list_available(repo = default_repo())
Arguments
repo |
character, a URL to the repository. Defaults to the official SIA repository. |
Do a welcome routine in the fresh SIA module project
Description
Do a welcome routine in the fresh SIA module project
Usage
welcome_routine()