You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Shiny项目makePage函数传参报错,寻求解决方案

解决Shiny项目中makePage函数的"unused argument"错误

错误原因

报错Error in makePage: unused argument (alist(div(HorizontalStack(makeCard(NULL, firstcard, size = 4, style = "max-height: 320px"))), ))的核心问题是:你定义的makePage函数仅接受title单个参数,但调用时传入了额外的页面内容参数,函数无法识别这个多余的参数。

查看代码细节:

  • helperfunctions.R中makePage的定义仅声明了title参数:
makePage <- function(title) {
  tagList(
    div(
      class = "page-title",
      span(
        title,
        class = "ms-fontSize-32 ms-fontWeight-semibold",
        style = "color: #323130"
      ),
    ),
    # contents
  )
}
  • 但在simsettings.R调用makePage时,你传入了第二个参数(卡片内容的div):
makePage(
    t("Simulatie instellingen"),
    div(
        HorizontalStack(
            makeCard(NULL, firstcard, size = 4, style = "max-height: 320px")
        )
    ),
)

修复方案

方案1:使用可变参数(推荐,适配多内容场景)

修改helperfunctions.R中的makePage函数,添加...可变参数来接收任意数量的页面内容:

makePage <- function(title, ...) {
  tagList(
    div(
      class = "page-title",
      span(
        title,
        class = "ms-fontSize-32 ms-fontWeight-semibold",
        style = "color: #323130"
      ),
    ),
    # 传入所有额外内容参数
    ...
  )
}

修改后,原调用代码无需调整即可正常运行。

方案2:使用明确的内容参数

如果希望参数更清晰,可定义content参数:

makePage <- function(title, content) {
  tagList(
    div(
      class = "page-title",
      span(
        title,
        class = "ms-fontSize-32 ms-fontWeight-semibold",
        style = "color: #323130"
      ),
    ),
    content
  )
}

此时调用时需指定参数名:

makePage(
    t("Simulatie instellingen"),
    content = div(
        HorizontalStack(
            makeCard(NULL, firstcard, size = 4, style = "max-height: 320px")
        )
    )
)

额外优化

simsettingspage的tagList末尾多了一个冗余逗号,建议去掉以保持代码整洁:

simsettingspage <- tagList(
    makePage(
        t("Simulatie instellingen"),
        div(
            HorizontalStack(
                makeCard(NULL, firstcard, size = 4, style = "max-height: 320px")
            )
        )
    ) # 移除此处的逗号
)

内容的提问来源于stack exchange,提问作者Elias

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.18 19:50:42