如何根据条件运行eventReactive?

时间:2018-06-07 06:49:45

标签: r shiny shiny-server

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

1 个答案:

答案 0 :(得分:0)

这样的事情可以起作用

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
})

希望这会有所帮助!!