【问题标题】:Passing reactive server values to modules将响应式服务器值传递给模块
【发布时间】:2019-09-10 10:03:18
【问题描述】:

我有一个像这样具有服务器功能的闪亮应用程序;

shinyServer(function(input, output) {
 chosen_fam <- reactive({ input$fam })

  output$newui <- renderUI({  NewProductUI("newproduct", fam = chosen_fam()) })
  output$newbtn <- renderUI({ NewProductButtonUI("newproduct", fam =  chosen_fam()) })

  callModule(NewProduct, id = "newproduct", fam =  chosen_fam())
})

NewProduct 模块内部有这样的东西:

NewProduct <- function(input, output, session, fam){
  observeEvent(input$submitnew, {
    print(paste0("Adding.... ", fam))

    row <- c(fam, input$variable)
    upload_to_googlesheets(token, row)
})

UI 会根据所选系列进行渲染,服务器模块也会根据系列执行不同的操作。

渲染 UI 似乎工作正常,但 callModule 中的“fam”变量没有更新(因此它始终是第一个选择的系列的结果)。来自输入的变量运行良好,所以我想这与范围界定有关(它可能正在“newproduct”命名空间中寻找“fam”?)。

如何明确告诉callModule 使用会话命名空间中的反应式表达式?或者有没有办法我可以将 fam 变量添加到“newproduct”命名空间?

【问题讨论】:

    标签: r shiny shiny-reactivity


    【解决方案1】:

    你必须给反应导体本身:

    callModule(NewProduct, id = "newproduct", fam =  chosen_fam)
    

    (无括号)。在模块中:

    row <- c(fam(), input$variable)
    

    (括号)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-05
      • 1970-01-01
      • 2013-01-12
      • 2015-02-28
      • 1970-01-01
      • 2021-02-19
      • 2022-01-14
      相关资源
      最近更新 更多