0
사용자 입력에 따라 매초 n 초마다 루프에서 코드를 실행하고 싶습니다. 나는 reactTimer()로 그것을한다.
앱이 파일에서 읽는 중이지만 더 이상 읽거나 버튼을 클릭 할 필요가없는 경우 루프를 종료하고 싶습니다. 어떤 조언반짝이는 reactTimer를 종료하는 방법
사용자 입력에 따라 매초 n 초마다 루프에서 코드를 실행하고 싶습니다. 나는 reactTimer()로 그것을한다.
앱이 파일에서 읽는 중이지만 더 이상 읽거나 버튼을 클릭 할 필요가없는 경우 루프를 종료하고 싶습니다. 어떤 조언반짝이는 reactTimer를 종료하는 방법
에 대한
observeEvent(input$start, {
autoInvalidate <- reactiveTimer(input$timerValue)
output$plot <- renderPlot({
autoInvalidate()
...code...
}
}
감사를 확실히 타이머를 중지하려면 당신은 당신이 당신을 실행하고 유지해야합니다 그렇지 않으면 reactiveTimer(Inf)
으로 설정할 수 있습니다, 다음과 같이
내 코드는 서버 측에 보인다 boolean을 사용하여 다음 예와 같이 상태를 저장하거나 해제 할 수 있습니다.
library(shiny)
shinyApp(ui=fluidPage(textOutput("mytext"),
actionButton("s0","manual"),
actionButton("s1","start"),
actionButton("s2","stop"),
actionButton("s3","terminate")),
server=function(input, output){
my<-reactiveValues(inc=0, timer=reactiveTimer(100), started=FALSE)
observeEvent(input$s0, {my$inc<-my$inc+1})
observeEvent(input$s1, {my$started<-TRUE})
observeEvent(input$s2, {my$started<-FALSE})
observeEvent(input$s3, {my$timer<-reactiveTimer(Inf)})
observe({
my$timer()
if(isolate(my$started))
my$inc<-isolate(my$inc)+1
})
output$mytext <- renderText(my$inc)
})
감사합니다. 대단히 감사합니다. – TomasG