다양한 입력으로 반짝이는 앱을 개발 중입니다. 일반적으로, 사용자가 입력 값을 받아들이도록 버튼을 누를 수있는 설정이 있습니다. 입력 값을 설정하면 설정해야 할 객체가 만들어집니다. 애니메이션은 사용자가 움직이는 sliderInput 객체에서 재생 버튼을 누를 때 실행되어야합니다. 생성 된 객체는 반복 될 때마다 업데이트됩니다.R 반짝이 : reactiveValues 개체의 값을 변경하는 방법
하나의 문제는 객체 중 하나가 reactiveValues 목록이라는 것입니다. 사용자가 설정을 변경하고 "수락"을 클릭하고 실행할 때마다 전체 개체 집합을 다시 만들 수 있습니다 (이전 값 지우기). 대신, reactiveValues 목록의 오브젝트는 겹쳐 쓰지 않지만 다음 설정으로 매번 증가됩니다. 따라서 각 객체 슬롯에는 실제로 여러 개의 객체가 있습니다.
최대 반복을 값으로 설정하고 수용을 누른 다음 값을 변경하고 다시 적용한 다음 재생을 클릭 해보십시오. 당신은 그것이 reactiveValues 객체의 다른 길이를 출력 할 것을 보게 될 것입니다.
rm()과 같은 몇 가지 시도를 시도하여 reactiveValues를 삭제하려고했습니다. 또한 나는 해결책을 여기 (shiny: How to update a reactiveValues object?) 시도했지만 그것은 작동하지 않았다.
library(shiny)
iter_test <- shinyApp(
ui=shinyUI(fluidPage(
titlePanel("title panel"),
sidebarLayout(position = "left",
sidebarPanel("Simulation parameters",
sliderInput("iter","Progress of simulation",value=1, min=1, max=30, round=TRUE, step=1,
animate=animationOptions(interval=1, loop=FALSE)),
actionButton('run',"Accept settings, press play above"),
sliderInput('max_iter','Maximum number of iterations',value=20, min=1, max=30, round=TRUE, step=1)
),
mainPanel( plotOutput("plots"))
)#end of layout
)
)#end of UI definition
,
server=shinyServer(function(input, output, session)
{
observeEvent(input$run, {
#only set up simulation objects if accept is clicked
updateSliderInput(session, "iter", label="Progress of simulation", value=1, min=1, max=input$max_iter, step=1)
#try(rm(params))
#set up objects needed for simulation
params <- reactiveValues(tmp=rep(1, input$max_iter))
#when the play button is pressed, the following loop should trigger.
observeEvent(input$iter, {
print(length(params$tmp))
})
})
}
)
)
나는 당신이 함께 일할 수있는 무언가를 가지고 있다고 생각하지만, 당신이 이것을 어디로 가는지 정말로 알지 못하기 때문에 완전히 확신 할 수는 없다. –