MCP HubMCP Hub
SKILL·BB62E4

build-shiny-module

pjt222
Обновлено 1 month ago
9 просмотров
26
3
26
Посмотреть на GitHub
Метаreactaitestingdesign

О программе

Этот навык помогает разработчикам создавать переиспользуемые модули Shiny с правильной изоляцией пространств имён с помощью NS(). Он охватывает создание пар UI/сервер, обработку реактивных возвращаемых значений, а также обеспечивает взаимодействие между модулями и вложенную композицию. Используйте его при выделении переиспользуемых компонентов из растущих приложений, инкапсуляции сложной логики или сборке крупных приложений из тестируемых блоков.

Быстрая установка

Claude Code

Рекомендуется
Основной
npx skills add pjt222/agent-almanac -a claude-code
Команда плагинаАльтернативный
/plugin add https://github.com/pjt222/agent-almanac
Git клонированиеАльтернативный
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/build-shiny-module

Скопируйте и вставьте эту команду в Claude Code для установки этого навыка

Документация

Build Shiny Module

Reusable Shiny UI/server module pairs w/ proper namespace isolation, reactive comm, composability.

Use When

  • Extract reusable component from growing Shiny app
  • UI widget used in many places
  • Encapsulate complex reactive logic behind clean interface
  • Compose larger apps from smaller testable units

In

  • Required: Module purpose + fn desc
  • Required: In/out contract (what module receives + returns)
  • Optional: Whether module nests others (default: no)
  • Optional: Framework ctx (golem, rhino, vanilla)

Do

Step 1: Define Interface

Before code, define accepts + returns:

Module: data_filter
Inputs: reactive dataset, column names to filter on
Outputs: reactive filtered dataset
UI: filter controls (selectInput, sliderInput, dateRangeInput)

Clear contract w/ reactive ins, reactive outs, UI elements.

If err: Interface unclear → module too broad. Split into smaller, single responsibilities.

Step 2: Module UI Fn

#' Data Filter Module UI
#'
#' @param id Module namespace ID
#' @return A tagList of filter controls
#' @export
dataFilterUI <- function(id) {
  ns <- NS(id)
  tagList(
    selectInput(
      ns("column"),
      "Filter column",
      choices = NULL
    ),
    uiOutput(ns("filter_control")),
    actionButton(ns("apply"), "Apply Filter", class = "btn-primary")
  )
}

Key rules:

  • Fn name: <name>UI convention
  • First arg always id
  • ns <- NS(id) at top
  • Wrap every inputId + outputId w/ ns()
  • Return tagList() for flexible placement

UI fn creates namespaced in/out elements.

If err: IDs collide when module used twice → check every ID wrapped w/ ns(). Common miss: IDs inside renderUI() or uiOutput() — also need ns().

Step 3: Module Server Fn

#' Data Filter Module Server
#'
#' @param id Module namespace ID
#' @param data Reactive expression returning a data frame
#' @param columns Character vector of filterable column names
#' @return Reactive expression returning the filtered data frame
#' @export
dataFilterServer <- function(id, data, columns) {
  moduleServer(id, function(input, output, session) {
    ns <- session$ns

    # Update column choices when data changes
    observeEvent(data(), {
      available <- intersect(columns, names(data()))
      updateSelectInput(session, "column", choices = available)
    })

    # Dynamic filter control based on selected column
    output$filter_control <- renderUI({
      req(input$column)
      col_data <- data()[[input$column]]

      if (is.numeric(col_data)) {
        sliderInput(
          ns("value_range"),
          "Range",
          min = min(col_data, na.rm = TRUE),
          max = max(col_data, na.rm = TRUE),
          value = range(col_data, na.rm = TRUE)
        )
      } else {
        selectInput(
          ns("value_select"),
          "Values",
          choices = unique(col_data),
          multiple = TRUE,
          selected = unique(col_data)
        )
      }
    })

    # Return filtered data as a reactive
    filtered <- eventReactive(input$apply, {
      req(input$column)
      col <- input$column
      df <- data()

      if (is.numeric(df[[col]])) {
        req(input$value_range)
        df[df[[col]] >= input$value_range[1] &
           df[[col]] <= input$value_range[2], ]
      } else {
        req(input$value_select)
        df[df[[col]] %in% input$value_select, ]
      }
    }, ignoreNULL = FALSE)

    return(filtered)
  })
}

Key rules:

  • Fn name: <name>Server convention
  • First arg always id
  • Additional args = reactive exprs or static values
  • Use moduleServer(id, function(input, output, session) { ... })
  • Use session$ns for dynamic UI inside server
  • Return reactive values explicitly

Server fn processes ins + returns reactive out.

If err: Reactives don't update → check ins from dynamic UI use session$ns (not outer ns). Module returns NULL → ensure return() is last expr in moduleServer().

Step 4: Wire Module into Parent

# In app_ui.R or ui
ui <- page_sidebar(
  title = "Analysis App",
  sidebar = sidebar(
    dataFilterUI("filter1")
  ),
  card(
    DT::dataTableOutput("table")
  )
)

# In app_server.R or server
server <- function(input, output, session) {
  # Raw data source
  raw_data <- reactive({ mtcars })

  # Call module — capture its return value
  filtered_data <- dataFilterServer(
    "filter1",
    data = raw_data,
    columns = c("cyl", "mpg", "hp", "wt")
  )

  # Use the module's returned reactive
  output$table <- DT::renderDataTable({
    filtered_data()
  })
}

Module appears in UI, returned reactive flows into downstream outs.

If err: UI doesn't render → verify id matches between UI + server calls. Returned reactive NULL → check server fn actually returns value.

Step 5: Nested Modules (Optional)

Modules containing other modules:

analysisUI <- function(id) {
  ns <- NS(id)
  tagList(
    dataFilterUI(ns("filter")),
    plotOutput(ns("plot"))
  )
}

analysisServer <- function(id, data) {
  moduleServer(id, function(input, output, session) {
    # Call inner module with namespaced ID
    filtered <- dataFilterServer("filter", data = data, columns = names(data()))

    output$plot <- renderPlot({
      req(filtered())
      plot(filtered())
    })

    return(filtered)
  })
}

Key: UI nests w/ ns("inner_id"). Server calls w/ just "inner_id"moduleServer handles namespace chaining.

Inner module renders correctly w/in outer's namespace.

If err: Inner UI doesn't appear → likely forgot ns() around inner ID in outer UI. Server comm breaks → check inner ID matches (no ns() in server call).

Step 6: Test in Isolation

# Quick test app for the module
if (interactive()) {
  shiny::shinyApp(
    ui = fluidPage(
      dataFilterUI("test"),
      DT::dataTableOutput("result")
    ),
    server = function(input, output, session) {
      data <- reactive(iris)
      filtered <- dataFilterServer("test", data, names(iris))
      output$result <- DT::renderDataTable(filtered())
    }
  )
}

Module works correctly in minimal test app.

If err: Fails in isolation but works in full app (or reverse) → implicit deps on global vars or parent session state.

Check

  • UI fn accepts id as first arg + uses NS(id)
  • Every in/out ID in UI wrapped w/ ns()
  • Server uses moduleServer(id, function(input, output, session) { ... })
  • Dynamic UI in server uses session$ns for IDs
  • Module instantiable many times w/o ID collisions
  • Reactive returns accessible to parent
  • Works in minimal standalone test

Traps

  • Forget ns() in renderUI(): Dynamic UI inside server must use session$ns — outer ns not available in moduleServer()
  • Non-reactive data: Args that change over time must be reactive. Pass reactive(data) not data
  • ID mismatch: id in UI call must exactly match id in server call
  • Not returning reactives: Module computes something parent needs → must return() reactive. Silent bug
  • Nested namespace: UI: ns("inner_id"). Server: just "inner_id". Mixing → double-wrapping or missing prefixes

  • scaffold-shiny-app — set up app structure before adding modules
  • test-shiny-app — test modules w/ testServer() unit tests
  • design-shiny-ui — bslib layout + theming for module UIs
  • optimize-shiny-performance — cache + async patterns w/in modules

GitHub репозиторий

pjt222/agent-almanac
Путь: i18n/caveman-ultra/skills/build-shiny-module
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams
FAQ

Frequently asked questions

What is the build-shiny-module skill?

build-shiny-module is a Claude Skill by pjt222. Skills package instructions and resources that Claude loads on demand, so Claude can perform build-shiny-module-related tasks without extra prompting.

How do I install build-shiny-module?

Use the install commands on this page: add build-shiny-module to Claude Code as a plugin, or clone its repository into your skills directory, then restart Claude so it picks up the skill.

What category does build-shiny-module belong to?

build-shiny-module is in the Meta category, tagged react, ai, testing and design.

Is build-shiny-module free to use?

Yes. build-shiny-module is listed on AIMCP and free to install. It runs inside Claude, so no separate service account is required to use the skill itself.

Похожие навыки

content-collections
Мета

Этот навык предоставляет проверенную в продакшене настройку для Content Collections — TypeScript-ориентированного инструмента, который преобразует файлы Markdown/MDX в типобезопасные коллекции данных с валидацией Zod. Используйте его при создании блогов, сайтов документации или контентных приложений на Vite + React для обеспечения типобезопасности и автоматической проверки содержимого. Он охватывает всё: от настройки плагина Vite и компиляции MDX до оптимизации развертывания и валидации схем.

Просмотреть навык
polymarket
Мета

Этот навык позволяет разработчикам создавать приложения на платформе прогнозных рынков Polymarket, включая интеграцию с API для торговли и получения рыночных данных. Он также обеспечивает потоковую передачу данных в реальном времени через WebSocket для отслеживания текущих сделок и рыночной активности. Используйте его для реализации торговых стратегий или создания инструментов, обрабатывающих обновления рынка в реальном времени.

Просмотреть навык
creating-opencode-plugins
Мета

Этот навык помогает разработчикам создавать плагины OpenCode, которые подключаются к более чем 25 типам событий, таким как команды, файлы и операции LSP. Он предоставляет структуру плагина, спецификации API событий и шаблоны реализации для модулей на JavaScript/TypeScript. Используйте его, когда вам нужно перехватывать, отслеживать или расширять жизненный цикл ассистента OpenCode AI с помощью пользовательской событийно-ориентированной логики.

Просмотреть навык
sglang
Мета

SGLang — это высокопроизводительный фреймворк для обслуживания больших языковых моделей (LLM), специализирующийся на быстрой структурированной генерации JSON, regex и рабочих процессов агентов с использованием кэширования префиксов RadixAttention. Он обеспечивает значительно более высокую скорость вывода, особенно для задач с повторяющимися префиксами, что делает его идеальным для сложных структурированных результатов и многократных диалогов. Выбирайте SGLang вместо альтернатив, таких как vLLM, когда вам требуется ограниченное декодирование или вы создаете приложения с интенсивным совместным использованием префиксов.

Просмотреть навык