| module_info | R Documentation |
current_module returns the information of the currently
running module. It looks up the .module_id variable in the calling
environment (set automatically when a module is loaded), then retrieves
the corresponding row from the module table.
active_module returns a reactive value with
information about the module that is currently visible in the iframe
tab (or the standalone module if no iframe manager is present).
Unlike current_module which is static and always returns the module
whose server code is running, active_module dynamically tracks
which module the user is looking at from any context.
switch_module programmatically switches the active
module in the dashboard UI.
It sends a shidashi.switch_module message to the JavaScript
front-end. When called from a module running inside an iframe, the
handler automatically forwards the request to the parent window via
postMessage so that the sidebar highlight, tab bar, and iframe
all update correctly.
module_info(root_path = template_root(), settings_file = "modules.yaml")
current_module(
session = shiny::getDefaultReactiveDomain(),
root_path = template_root()
)
active_module(
session = shiny::getDefaultReactiveDomain(),
root_path = template_root()
)
switch_module(module_id, session = shiny::getDefaultReactiveDomain())
load_module(
root_path = template_root(),
request = list(QUERY_STRING = "/"),
env = parent.frame()
)
root_path |
the root path of the website project |
settings_file |
the settings file containing the module information |
session |
shiny reactive domain; used to extract the module id from
the URL query string when |
module_id |
character string; the target module identifier (must match an entry in ‘modules.yaml’). |
request |
'HTTP' request string |
env |
environment to load module variables into |
The module files are stored in modules/ folder in your
project. The folder names are the module id. Within each folder,
there should be one "server.R", R/, and a
"module-ui.html".
The R/ folder stores R code files that generate variables,
which will be available to the other two files. These variables, along
with some built-ins, will be used to render "module-ui.html".
The built-in functions are
shiny name-space function; should be used to generate the id for inputs and outputs. This strategy avoids conflict id effectively.
a variable of the module id
a function that returns the module label
The "server.R" has access to all the code in R/ as well.
Therefore it is highly recommended that you write each 'UI' component
side-by-side with their corresponding server functions and call
these server functions in "server.R".
active_module works by reading the
'@shidashi_active_module@' Shiny input that is set by the
JavaScript front-end whenever a module tab is activated.
Because it accesses session$rootScope()$input, the return value
is reactive: when called inside an observe or reactive
context it will re-fire whenever the user switches modules.
If the input has not been set yet (e.g. before any module is opened),
the function falls back to current_module().
A data frame with the following columns that contain the module information:
idmodule id, folder name
orderdisplay order in side-bar
groupgroup menu name if applicable, otherwise NA
labelthe readable label to be displayed on the side-bar
iconicon that will be displayed ahead of label, will be
passed to as_icon
badgebadge text that will be displayed
following the module label, will be passed to as_badge
urlthe relative 'URL' address of the module.
current_module: a named list with id, group,
label, icon, badge, and url of the current
module, or NULL if no module is active.
active_module: a named list with id, group,
label, icon, badge, and url of the
currently active (visible) module, or NULL if no module is active.
library(shiny)
module_info()
# load master module
load_module()
# load specific module
module_data <- load_module(
request = list(QUERY_STRING = "/?module=module_id"))
env <- module_data$environment
if (interactive()) {
# get module title
env$module_title()
# generate module-specific shiny id
env$ns("input1")
# generate part of the UI
env$ui()
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.