我想要两个不同的事件来触发我的应用程序中各种图表/输出所使用的数据的更新.一个是单击按钮(input$spec_button),另一个是点击点上的点(mainplot.click$click).
基本上,我想同时列出两者,但我不知道如何编写代码.这就是我现在拥有的:
在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
}
})
Run Code Online (Sandbox Code Playgroud)
但if-else子句不起作用
Error in mainplot.click$click | input$spec_button :
operations are possible only for numeric, logical or complex types
- >我可以使用某种动作组合器功能用于该mainplot.click$click | input$spec_button子句吗?
Dun*_*own 84
我知道这是旧的,但我有同样的问题.我终于弄明白了.您在大括号中包含一个表达式,只需列出事件/反应对象.我的(未经证实的)猜测是,闪亮只是对该表达式块执行与标准reactive块相同的反应指针分析.
observeEvent({
input$spec_button
mainplot.click$click
1
}, { ... } )
Run Code Online (Sandbox Code Playgroud)
小智 45
也:
observeEvent(c(
input$spec_button,
mainplot.click$click
), { ... } )
Run Code Online (Sandbox Code Playgroud)
我已经通过创建一个反应对象解决了这个问题,并在事件更改表达中使用它.如下:
xxchange <- reactive({
paste(input$filter , input$term)
})
output$mypotput <- eventReactive( xxchange(), {
...
...
...
} )
Run Code Online (Sandbox Code Playgroud)
这仍然可以通过 eventReactive 将您的操作放入向量中来完成。
eventReactive(
c(input$spec_button, mainplot.click$click),
{ ... } )
Run Code Online (Sandbox Code Playgroud)
这是我提出的解决方案:基本上,创建一个空reactiveValues数据持有者,然后根据两个单独的observeEvent实例修改其值.
data <- reactiveValues()
observeEvent(input$spec_button, {
data$data <- get.focus.spec(input=input, premise=premise,
itemname=input$dropdown.itemname, spec.info=spec.info)
})
observeEvent(mainplot.click$click, {
data$data <- get.focus.spec(input=input, premise=premise, mainplot=mainplot(),
mainplot.click_focus=mainplot.click_focus(),
spec.info=spec.info)
})
Run Code Online (Sandbox Code Playgroud)