MCP HubMCP Hub
Volver a habilidades

design-shiny-ui

pjt222
Actualizado 6 days ago
16 vistas
17
2
17
Ver en GitHub
Metadesign

Acerca de

Esta habilidad ayuda a los desarrolladores a construir interfaces de usuario modernas para aplicaciones Shiny utilizando bslib para temas y diseños responsivos. Cubre la creación de cuadrículas con layout_columns, la implementación de cajas de valor/tarjetas, y la aplicación de CSS/SCSS personalizado para branding. Úsela al comenzar una nueva aplicación Shiny, al modernizar desde fluidPage, o al mejorar la capacidad de respuesta y accesibilidad.

Instalación rápida

Claude Code

Recomendado
Principal
npx skills add pjt222/agent-almanac -a claude-code
Comando PluginAlternativo
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternativo
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/design-shiny-ui

Copia y pega este comando en Claude Code para instalar esta habilidad

Documentación

設 Shiny UI

以 bslib 題、現代布局原、自定 CSS 設響、可訪 Shiny 介。

  • 從始建新 Shiny UI
  • 舊 app 由 fluidPage 現代化至 bslib
  • 施品題(色、字)於 Shiny
  • 使 Shiny 於諸屏響
  • 改 Shiny 可訪

  • :app 用與目眾
  • :布類(sidebar、navbar、fillable、dashboard)
  • :品色與字
  • :用自定 CSS/SCSS(默:僅 bslib)
  • :可訪求(WCAG 級)

一:擇頁布

bslib 供諸頁構:

# Sidebar layout — most common for data apps
ui <- page_sidebar(
  title = "My App",
  sidebar = sidebar("Controls here"),
  "Main content here"
)

# Navbar layout — for multi-page apps
ui <- page_navbar(
  title = "My App",
  nav_panel("Tab 1", "Content 1"),
  nav_panel("Tab 2", "Content 2"),
  nav_spacer(),
  nav_item(actionButton("help", "Help"))
)

# Fillable layout — content fills available space
ui <- page_fillable(
  card(
    full_screen = TRUE,
    plotOutput("plot")
  )
)

# Dashboard layout — grid of value boxes and cards
ui <- page_sidebar(
  title = "Dashboard",
  sidebar = sidebar(open = "closed", "Filters"),
  layout_columns(
    fill = FALSE,
    value_box("Revenue", "$1.2M", theme = "primary"),
    value_box("Users", "4,521", theme = "success"),
    value_box("Uptime", "99.9%", theme = "info")
  ),
  layout_columns(
    card(plotOutput("chart1")),
    card(plotOutput("chart2"))
  )
)

得:布符 app 之導航與內容需。

敗:布不適→查用 page_sidebar() / page_navbar()(bslib),非 fluidPage() / navbarPage()(base shiny)。bslib 默認更佳且支題。

二:配 bslib 題

my_theme <- bslib::bs_theme(
  version = 5,                      # Bootstrap 5
  bootswatch = "flatly",            # Optional preset theme
  bg = "#ffffff",                   # Background color
  fg = "#2c3e50",                   # Foreground (text) color
  primary = "#2c3e50",              # Primary brand color
  secondary = "#95a5a6",            # Secondary color
  success = "#18bc9c",
  info = "#3498db",
  warning = "#f39c12",
  danger = "#e74c3c",
  base_font = bslib::font_google("Source Sans Pro"),
  heading_font = bslib::font_google("Source Sans Pro", wght = 600),
  code_font = bslib::font_google("Fira Code"),
  "navbar-bg" = "#2c3e50"
)

ui <- page_sidebar(
  theme = my_theme,
  title = "Themed App",
  # ...
)

開發時用互動題編:

bslib::bs_theme_preview(my_theme)

得:app 以一致品色、字、Bootstrap 5 組件現。

敗:字不載→查網(Google Fonts 需之)或換系字:font_collection("system-ui", "-apple-system", "Segoe UI")。題變量不施→查 theme 傳至頁函。

三:以卡與列建布

ui <- page_sidebar(
  theme = my_theme,
  title = "Analysis Dashboard",
  sidebar = sidebar(
    width = 300,
    title = "Filters",
    selectInput("dataset", "Dataset", choices = c("iris", "mtcars")),
    sliderInput("sample", "Sample %", 10, 100, 100, step = 10),
    hr(),
    actionButton("refresh", "Refresh", class = "btn-primary w-100")
  ),

  # KPI row — non-filling
  layout_columns(
    fill = FALSE,
    col_widths = c(4, 4, 4),
    value_box(
      title = "Observations",
      value = textOutput("n_obs"),
      showcase = bsicons::bs_icon("table"),
      theme = "primary"
    ),
    value_box(
      title = "Variables",
      value = textOutput("n_vars"),
      showcase = bsicons::bs_icon("columns-gap"),
      theme = "info"
    ),
    value_box(
      title = "Missing",
      value = textOutput("n_missing"),
      showcase = bsicons::bs_icon("exclamation-triangle"),
      theme = "warning"
    )
  ),

  # Main content row
  layout_columns(
    col_widths = c(8, 4),
    card(
      card_header("Distribution"),
      full_screen = TRUE,
      plotOutput("main_plot")
    ),
    card(
      card_header("Summary"),
      tableOutput("summary_table")
    )
  )
)

諸布原:

  • layout_columns() — 響格,含 col_widths
  • card() — 內容器,可選頭/尾
  • value_box() — KPI 顯,含徽與題
  • layout_sidebar() — 卡內嵌 sidebar
  • navset_card_tab() — 有頁標之卡

得:響格布應屏尺。

敗:寬屏列意外堆→查 col_widths 和為 12(Bootstrap 格)。卡重疊→非填列宜 fill = FALSE

四:添動 UI 素

server <- function(input, output, session) {
  output$dynamic_filters <- renderUI({
    data <- current_data()
    tagList(
      selectInput("col", "Column", choices = names(data)),
      if (is.numeric(data[[input$col]])) {
        sliderInput("range", "Range",
          min = min(data[[input$col]], na.rm = TRUE),
          max = max(data[[input$col]], na.rm = TRUE),
          value = range(data[[input$col]], na.rm = TRUE)
        )
      } else {
        selectInput("values", "Values",
          choices = unique(data[[input$col]]),
          multiple = TRUE
        )
      }
    )
  })

  # Conditional panels (no server round-trip)
  # In UI:
  # conditionalPanel(
  #   condition = "input.show_advanced == true",
  #   numericInput("alpha", "Alpha", 0.05)
  # )
}

得:UI 素依使擇及數動更。

敗:動 UI 閃→用 conditionalPanel()(CSS 基)代 renderUI()。動入於再渲失值→加 session$sendInputMessage() 復態。

五:添自定 CSS/SCSS(可選)

求 bslib 題變量外之樣:

# Inline CSS
ui <- page_sidebar(
  theme = my_theme,
  tags$head(tags$style(HTML("
    .sidebar { border-right: 2px solid var(--bs-primary); }
    .card-header { font-weight: 600; }
    .value-box .value { font-size: 2.5rem; }
  "))),
  # ...
)

# External CSS file (place in www/ directory)
ui <- page_sidebar(
  theme = my_theme,
  tags$head(tags$link(rel = "stylesheet", href = "custom.css")),
  # ...
)

SCSS 與 bslib 整合:

my_theme <- bslib::bs_theme(version = 5) |>
  bslib::bs_add_rules(sass::sass_file("www/custom.scss"))

得:自定樣施而不破 bslib 題。

敗:自定 CSS 與 bslib 衝→用 Bootstrap CSS 變量(var(--bs-primary))代硬編色→題變則自定樣傳播。

六:保可訪

# Add ARIA labels to inputs
selectInput("category", "Category",
  choices = c("A", "B", "C")
) |> tagAppendAttributes(`aria-describedby` = "category-help")

# Add alt text to plots
output$plot <- renderPlot({
  plot(data(), main = "Distribution of Values")
}, alt = "Histogram showing the distribution of selected values")

# Ensure sufficient color contrast in theme
my_theme <- bslib::bs_theme(
  version = 5,
  bg = "#ffffff",      # White background
  fg = "#212529"       # Dark text — 15.4:1 contrast ratio
)

# Use semantic HTML
tags$main(
  role = "main",
  tags$h1("Dashboard"),
  tags$section(
    `aria-label` = "Key Performance Indicators",
    layout_columns(
      # value boxes...
    )
  )
)

得:app 符 WCAG 2.1 AA 之色對、鍵導、屏讀相容。

敗:用瀏覽器開發工具 Lighthouse 可訪審試。以 WebAIM 對比查色對。保諸互動素可鍵焦。

  • 頁布於桌與手寬皆正渲
  • bslib 題一致施於諸組件
  • value box 以正題及徽顯
  • 卡於響格正縮
  • 自定 CSS 用 Bootstrap 變量,非硬編
  • 諸圖有 alt 文為屏讀
  • 色對符 WCAG AA(文 4.5:1)
  • 互動素可鍵訪

  • 混新舊 Shiny UI:勿混 fluidPage() 與 bslib 組件→專用 page_sidebar()page_navbar()、或 page_fillable()
  • CSS 硬編色:用 var(--bs-primary)#2c3e50→硬編色題變則破
  • 非填列忘 fill = FALSE:value box 列與摘列常不宜伸→設 fill = FALSE
  • 離網境之 Google Fonts:部至隔網→用系字或自寓字檔代 font_google()
  • 略手機:以瀏覽器響模試。layout_columns 窄屏自動堆,自定 CSS 則或否

  • scaffold-shiny-app
  • build-shiny-module
  • optimize-shiny-performance
  • review-web-design
  • review-ux-ui

Repositorio GitHub

pjt222/agent-almanac
Ruta: i18n/wenyan-ultra/skills/design-shiny-ui
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Habilidades relacionadas

content-collections

Meta

Esta habilidad proporciona una configuración probada en producción para Content Collections, una herramienta centrada en TypeScript que transforma archivos Markdown/MDX en colecciones de datos con tipado seguro mediante validación Zod. Úsala al construir blogs, sitios de documentación o aplicaciones Vite + React con mucho contenido para garantizar seguridad de tipos y validación automática de contenido. Abarca todo, desde la configuración del plugin de Vite y compilación MDX hasta la optimización de despliegue y validación de esquemas.

Ver habilidad

polymarket

Meta

Esta habilidad permite a los desarrolladores crear aplicaciones con la plataforma de mercados de predicción Polymarket, incluyendo la integración de API para operaciones y datos de mercado. También proporciona transmisión de datos en tiempo real a través de WebSocket para monitorear operaciones en vivo y actividad del mercado. Úsela para implementar estrategias de trading o crear herramientas que procesen actualizaciones de mercado en tiempo real.

Ver habilidad

creating-opencode-plugins

Meta

Esta habilidad ayuda a los desarrolladores a crear complementos de OpenCode que se conectan a más de 25 tipos de eventos, como comandos, archivos y operaciones LSP. Proporciona la estructura del complemento, las especificaciones de la API de eventos y los patrones de implementación para módulos en JavaScript/TypeScript. Úsala cuando necesites interceptar, monitorear o extender el ciclo de vida del asistente de IA de OpenCode con lógica personalizada basada en eventos.

Ver habilidad

sglang

Meta

SGLang es un framework de alto rendimiento para el servicio de LLM que se especializa en generación rápida y estructurada para JSON, expresiones regulares y flujos de trabajo de agentes utilizando su caché de prefijos RadixAttention. Ofrece una inferencia significativamente más rápida, especialmente para tareas con prefijos repetidos, lo que lo hace ideal para salidas complejas y estructuradas, y conversaciones multiturno. Elige SGLang sobre alternativas como vLLM cuando necesites decodificación restringida o estés construyendo aplicaciones con uso extensivo de prefijos compartidos.

Ver habilidad