저는 R Studio의 Shiny를 사용하여 애니메이션 그래프 프로젝트를 구성 중입니다. 현재 "가!" 버튼을 누르면 애니메이션이 시작됩니다. "재설정"버튼을 사용하여 변수를 다시 초기화하고 애니메이션을 다시 실행하고 싶습니다. 그러나 Shiny가 코드 내에서 입력 $ 버튼 값을 변경할 수 없기 때문에이 작업을 수행하는 방법에 대해 고민하고 있습니다. 실제 프로젝트는 아래의 샘플 블록과 형태가 비슷하지만 훨씬 더 복잡합니다. 애니메이션은 전달되는 정보에 필수적입니다. 프로젝트가 완료되면 Shiny 서버에 배포 할 예정이므로 사용자가 링크를 다시 열지 않고도 여러 선택 항목을 사용하여 애니메이션을 다시 실행할 수 있기를 바랍니다.Shiny R Studio에서 애니메이션 재설정
# ui.R
library(shiny)
shinyUI(fluidPage(
# Application title
headerPanel("Cost Explorer"),
sidebarPanel(
actionButton("goButton", "Go!"),
actionButton("reset", "Reset"),
sliderInput("myvar", label=h6("Variability of cost"),
min=0, max=50, value=10)
),
mainPanel(
plotOutput(outputId="tsplot")
)
))
# server.R
library(shiny)
shinyServer(function(input, output, session) {
# initialize reactive values
ts <- reactiveValues(cost=rep(NA,100), year=(2010:2109), counter=1)
output$tsplot <- renderPlot({
plot(ts$year, ts$cost, xlim=c(2010,2110), ylim=c(-200,200), xlab="Year",
ylab="Cost (US Dollars)", type="l", main="Forecasted Cost Time series")
})
observe({
isolate({
if (ts$counter==1){
ts$cost[ts$counter]=50 #initial cost
}
if (ts$counter > 1){
ts$cost[ts$counter]=ts$cost[ts$counter-1]+rnorm(1,0,input$myvar)
}
ts$counter=ts$counter+1
})
if (((isolate(ts$counter) < 100)) & (input$goButton > 0)){
invalidateLater(200, session)
}
if (input$reset > 0){
# How do I add reset functionality?
}
})
})