【问题标题】:moduleServer does not have the ... to add additional parameters to the module function like callModulemoduleServer 没有 ... 向模块函数添加附加参数,如 callModule
【发布时间】:2021-12-01 02:30:23
【问题描述】:

根据文档:

注意:从 Shiny 1.5.0 开始,我们建议使用 moduleServer() 而不是 callModule(),因为语法更容易理解,并且 使用 moduleServer 创建的模块可以使用 testServer() 进行测试。

但这里是 callModule 的文档:

用法

callModule(module, id, ..., session = getDefaultReactiveDomain())

参数

  • module A Shiny 模块服务器函数
  • id 一个 ID 字符串,与用于调用 模块的UI功能
  • ...要传递给模块服务器函数的附加参数
  • session 从中创建子作用域的会话(几乎应始终使用默认值)

这是moduleServer 的文档:

用法

moduleServer(id, module, session = getDefaultReactiveDomain())

参数

  • id 与用于调用模块 UI 函数的 ID 对应的 ID 字符串。
  • module 一个闪亮的模块服务器函数。
  • session 从中创建子作用域的会话(几乎应始终使用默认值)。

如何在没有... 的情况下向服务器函数添加其他参数?

【问题讨论】:

  • 查看示例here
  • 没有演示如何给模块函数添加额外的参数
  • moduleServer 存在于您创建的函数中,该函数可以有任意数量的参数。
  • @TTS 你能用一个例子添加答案吗?伪代码很好

标签: r shiny


【解决方案1】:

moduleServer 将存在于您创建的模块的服务器端部分中。它仅包含 id 和 module 本身。 employeeInfoServer 传递 id 以及 employee_。这可以传递任意数量的附加参数,例如function(id, employee_, hair_color, eye_color, city) 等......然后可以在moduleServer 中访问这些变量

employeeInfoServer <- function(id, employee_) {
  moduleServer(
    id,
    function(input, output, session) {
      output$job_title<- renderUI({
        h3(users[match(employee_, users$Name), "Job Title"]) 
      })
    }
  )
}

...也许这更有意义。 yourmoduleServer 是您正在创建的模块的服务器端。

yourmoduleServer <- function(id, ...) {
  moduleServer(id, module)
}

【讨论】:

  • 如果模块函数有额外的参数,比如module = function(input, output, session, param_1, param_2)。这种情况下moduleServer怎么设置param_1和param_2呢?
猜你喜欢
  • 1970-01-01
  • 2021-11-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-16
  • 1970-01-01
  • 1970-01-01
  • 2011-09-15
  • 2011-05-27
相关资源
最近更新 更多