Shiny의 반응성 행동에 대해 아래의 간단한 코드를 사용하여 약간의 명확성을 얻으려고합니다.Shiny Reactivity Explaination (ObserveEvent 사용)
y가 앱에서 업데이트되면 그래프가 업데이트됩니다.
x가 앱에서 업데이트되면 그래프가 업데이트되지 않습니다.
Shiny의 튜토리얼을 읽었으며 observeEvent에서 test() 및 plot() 함수를 모두 래핑 했으므로 두 매개 변수가 변경 될 때 그래프가 업데이트되지 않아야합니다.
누군가가이 논리를 설명하는 데 도움을 줄 수 있습니까?
library(shiny)
test <- function(x){x*2}
shinyServer(function(input, output, session) {
observeEvent(input$run, {
x = test(input$x)
output$distPlot <- renderPlot({
if(input$y){
x = x+2
}
plot(x)
})
})
})
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
numericInput("x", "x:", 10),
checkboxInput("y", label = "y", value = FALSE),
actionButton("run", "run")
),
mainPanel(
plotOutput("distPlot")
)
)
))
정말 감사합니다. 지금 많은 의미가 있습니다. – hjw