{{id}}_module_ui <- function(id) {
  ns <- shiny::NS(id)
  tagList(
    # UI

```r} } input_task_button(ns("run"), "Run module {{id}}", type = "default", icon = icon("arrow-turn-down")), downloadButton(ns("download"), "Download")

```r} }
    input_task_button(ns("run"), "Run module {{id}}", type = "default", icon = icon("arrow-turn-down"))
  )
}

{{id}}_module_server <- function(id, common, parent_session, map) {
  moduleServer(id, function(input, output, session) {

```r} } shinyjs::hide("download")

```r
  # create the asynchronous task
  common$tasks${{id}} <- ExtendedTask$new(function(...) {
    mirai::mirai(run(...), environment(), .args = list(run = {{id}}))
  }) |> bind_task_button("run")

    observeEvent(input$run, {
      # WARNING ####

      # FUNCTION CALL ####
      common$logger |> writeLog(type = "starting", "Starting to run {{id}}")
      # invoke the async task
      common$tasks${{id}}$invoke()
      # reactivate the results observer if it has already been used
      results$resume()

      # METADATA ####
      # Populate using metadata()
    })


    results <- observe({
      # LOAD INTO COMMON ####

      # fetch the result
      result <- common$tasks${{id}}$result()
      # suspend the observer
      results$suspend()

      # check the class of the result is the class when the function runs successfully
      if (class(result) == "list"){

        common$logger |> writeLog(type = "complete", "{{id}} has completed")

        # TRIGGER
        trigger("{{id}}")

```r} } shinyjs::show("download")

```r} }
        # explicitly call the mapping function
        do.call("{{id}}_module_map", list(map, common))
        show_map(parent_session)
        # set an input value to use in testing
        shinyjs::runjs("Shiny.setInputValue('{{id}}-complete', 'complete');")
      } else {
        common$logger |> writeLog(type = "error", result)
      }
    })

```r} }

output$result <- renderText({
  watch("{{id}}")
  # Result
})
```r} }
  output$download <- downloadHandler(
    filename = function() {
      "placeholder.ext"
    },
    content = function(file) {
      # Download content
    })

```r} } return(list( save = function() { # Save any values that should be saved when the current session is saved # Populate using save_and_load() }, load = function(state) { # Load # Populate using save_and_load() } ))

```r
  })
}

```r} }
{{id}}_module_result <- function(id) {
  ns <- NS(id)

  # Result UI
  verbatimTextOutput(ns("result"))
}

```r} } {{id}}_module_map <- function(map, common) { # Map logic }

```r} }
{{id}}_module_rmd <- function(common) {
  # Variables used in the module's Rmd code
  # Populate using metadata()
}


Try the shinyscholar package in your browser

Any scripts or data that you put into this service are public.

shinyscholar documentation built on Sept. 9, 2025, 5:52 p.m.