如何根据条件 运行 eventReactive?

How to run eventReactive based on condition?

我正在构建一个闪亮的应用程序,它根据不同的功能计算潜在分数。在此应用程序中,有 "numericInput" 个框允许用户为特征分配权重。如果所有权重的总和不等于 1(即 100%),我想弹出模型对话框。我想用 eventReactive 弹出这个。如果所有权重的总和为 1,则应执行以下代码,否则应弹出 modelDialog。请提出解决方案

类似这样的方法可行

score = eventReactive(input$some_trigger,{
  if(sum(input_weights) != 1){
    showModal(
      modalDialog(
        tags$p("The sum of your weights are not adding up to 1. Please correct the accordingly"),
        title = "Error: Incorrect weights"
      )
    )
  }
  req(sum(input_weights) == 1)
   #continue with calculation of score
})

希望对您有所帮助!!