如何在 Shiny eventReactive 处理程序中侦听多个事件表达式 [英] How to listen for more than one event expression within a Shiny eventReactive handler

查看:87
本文介绍了如何在 Shiny eventReactive 处理程序中侦听多个事件表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要两个不同的事件来触发我的应用程序中各种绘图/输出正在使用的数据的更新.一个是被点击的按钮(input$spec_button),另一个是被点击的点上的一个点(mainplot.click$click).

I want two different events to trigger an update of the data being used by various plots / outputs in my app. One is a button being clicked (input$spec_button) and the other is a point on a dot being clicked (mainplot.click$click).

基本上,我想同时列出两者,但我不确定如何编写代码.这是我现在所拥有的:

Basically, I want to listed for both at the same time, but I'm not sure how to write the code. Here's what I have now:

在 server.R 中:

in server.R:

data <- eventReactive({mainplot.click$click | input$spec_button}, {
    if(input$spec_button){
      # get data relevant to the button
    } else {
      # get data relevant to the point clicked
    }
  })

但是 if-else 子句不起作用

But the if-else clause doesn't work

mainplot.click$click 中的错误 |输入$spec_button :操作仅适用于数字、逻辑或复杂类型

--> 是否有某种动作组合函数可以用于 mainplot.click$click |input$spec_button 子句?

--> Is there some sort of action-combiner function I can use for the mainplot.click$click | input$spec_button clause?

推荐答案

我知道这是旧的,但我有同样的问题.我终于弄明白了.您在大括号中包含一个表达式并简单地列出事件/反应对象.我的(未经证实的)猜测是,shiny 只是对该表达式块执行与标准 reactive 块相同的反应式指针分析.

I know this is old, but I had the same question. I finally figured it out. You include an expression in braces and simply list the events / reactive objects. My (unsubstantiated) guess is that shiny simply performs the same reactive pointer analysis to this expression block as to a standard reactive block.

observeEvent({ 
  input$spec_button
  mainplot.click$click
  1
}, { ... } )

编辑

已更新以处理表达式中的最后一行返回 NULL 的情况.只需返回一个常量值.

Updated to handle the case where the last line in the expression returns NULL. Simply return a constant value.

这篇关于如何在 Shiny eventReactive 处理程序中侦听多个事件表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆