Shiny eventReactive 핸들러 내에서 둘 이상의 이벤트 표현식을 수신하는 방법
내 앱의 다양한 플롯 / 출력에서 사용되는 데이터의 업데이트를 트리거하는 두 가지 다른 이벤트를 원합니다. 하나는 클릭되는 버튼 ( 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
}
})
그러나 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절에 사용할 수있는 일종의 동작 결합 기능이 있습니까?
나는 이것이 오래되었다는 것을 알고 있지만 같은 질문이 있었다. 나는 마침내 그것을 알아 냈습니다. 중괄호 안에 표현식을 포함하고 단순히 이벤트 / 반응 객체를 나열합니다. 내 (확실하지 않은) 추측은 shiny가이 표현식 블록에 대해 표준 reactive블록 과 동일한 반응 포인터 분석을 수행한다는 것 입니다.
observeEvent({
input$spec_button
mainplot.click$click
}, { ... } )
또한:
observeEvent(c(
input$spec_button,
mainplot.click$click
), { ... } )
반응 객체를 생성하여이 문제를 해결하고 이벤트 변경 표현에 사용했습니다. 아래:
xxchange <- reactive({
paste(input$filter , input$term)
})
output$mypotput <- eventReactive( xxchange(), {
...
...
...
} )
내가 생각 해낸 해결책은 다음과 같습니다. 기본적으로 빈 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)
})
'IT박스' 카테고리의 다른 글
| SQL Server에 파일 저장 (0) | 2020.10.24 |
|---|---|
| Android Studio의 에뮬레이터가 시작되지 않음 (0) | 2020.10.24 |
| Spring autowiring에서 하위 패키지를 제외 하시겠습니까? (0) | 2020.10.23 |
| PyCharm에서 마지막 위치로 돌아가는 방법은 무엇입니까? (0) | 2020.10.23 |
| Rails 4 : 테스트 데이터베이스를 재설정하는 방법? (0) | 2020.10.23 |