EVOLUTION-MANAGER
Edit File: moduleServer.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Shiny modules</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for moduleServer {shiny}"><tr><td>moduleServer {shiny}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Shiny modules</h2> <h3>Description</h3> <p>Shiny's module feature lets you break complicated UI and server logic into smaller, self-contained pieces. Compared to large monolithic Shiny apps, modules are easier to reuse and easier to reason about. See the article at <a href="http://shiny.rstudio.com/articles/modules.html">http://shiny.rstudio.com/articles/modules.html</a> to learn more. </p> <h3>Usage</h3> <pre> moduleServer(id, module, session = getDefaultReactiveDomain()) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>id</code></td> <td> <p>An ID string that corresponds with the ID used to call the module's UI function.</p> </td></tr> <tr valign="top"><td><code>module</code></td> <td> <p>A Shiny module server function.</p> </td></tr> <tr valign="top"><td><code>session</code></td> <td> <p>Session from which to make a child scope (the default should almost always be used).</p> </td></tr> </table> <h3>Details</h3> <p>Starting in Shiny 1.5.0, we recommend using <code>moduleServer</code> instead of <code><a href="callModule.html">callModule()</a></code>, because the syntax is a little easier to understand, and modules created with <code>moduleServer</code> can be tested with <code><a href="testServer.html">testServer()</a></code>. </p> <h3>Value</h3> <p>The return value, if any, from executing the module server function </p> <h3>See Also</h3> <p><a href="http://shiny.rstudio.com/articles/modules.html">http://shiny.rstudio.com/articles/modules.html</a> </p> <h3>Examples</h3> <pre> # Define the UI for a module counterUI <- function(id, label = "Counter") { ns <- NS(id) tagList( actionButton(ns("button"), label = label), verbatimTextOutput(ns("out")) ) } # Define the server logic for a module counterServer <- function(id) { moduleServer( id, function(input, output, session) { count <- reactiveVal(0) observeEvent(input$button, { count(count() + 1) }) output$out <- renderText({ count() }) count } ) } # Use the module in an app ui <- fluidPage( counterUI("counter1", "Counter #1"), counterUI("counter2", "Counter #2") ) server <- function(input, output, session) { counterServer("counter1") counterServer("counter2") } if (interactive()) { shinyApp(ui, server) } # If you want to pass extra parameters to the module's server logic, you can # add them to your function. In this case `prefix` is text that will be # printed before the count. counterServer2 <- function(id, prefix = NULL) { moduleServer( id, function(input, output, session) { count <- reactiveVal(0) observeEvent(input$button, { count(count() + 1) }) output$out <- renderText({ paste0(prefix, count()) }) count } ) } ui <- fluidPage( counterUI("counter", "Counter"), ) server <- function(input, output, session) { counterServer2("counter", "The current count is: ") } if (interactive()) { shinyApp(ui, server) } </pre> <hr /><div style="text-align: center;">[Package <em>shiny</em> version 1.5.0 <a href="00Index.html">Index</a>]</div> </body></html>