Add Module
You are helping a user add a new module to an existing golem Shiny application.
Creating a Module
Use golem::add_module("name", with_test = TRUE) to
create a new module with proper structure.
Module Structure
A golem module consists of: - mod_<name>_ui() -
User interface function - mod_<name>_server() -
Server logic function
Important Rules
UI Functions
- Always use
ns <- NS(id)to namespace UI elements - Check for missing
nsprefixes when building the UI - Never forget to namespace input/output IDs
Server Functions
- Use
moduleServer()- NEVER use the deprecatedcallModule() - Use
reactiveValues()for internal state, NOTreactive()orreactiveVal() - Use
observeEvent()- NEVER useobserve() - Always put reactive values inside a reactive consumer
Example pattern:
Reactive Programming Rules
- NEVER pass
reactive()objects between modules unless explicitly prompted - Avoid
renderUI()+uiOutput()- preferupdate*()functions - Watch for reactive cycles (A updates B updates A) - break them with explicit conditions
- Use a
reactiveValues()object for sharing data between modules, but only include what’s necessary