案例研究:使用 R 的 Shiny 建置網頁應用程式
Dean Attali
Shiny Consultant
reactive() 和 input$ 都是反應式x <- reactive({
y() * input$num1 * input$num2
})
isolate() 避免建立反應式相依isolate() 內的反應值改變,不會觸發任何事x <- reactive({
y() * isolate({ input$num1 }) * input$num2
})
x <- reactive({
y() * isolate({ input$num1 * input$num2 })
})
有時你會想隔離所有反應式
x <- reactive({
isolate({
y() * input$num1 * input$num2
})
})
需要一種方式在需要時觸發 x 重新執行
actionButton(inputId, label, ...)

# 點擊按鈕兩次後
str(input$button)
int 2
在 server 端存取按鈕輸入值會觸發反應性
在 UI 加入按鈕
actionButton(inputId = "calculate_x", label = "Calculate x!")
存取按鈕以建立相依關係
x <- reactive({
input$calculate_x
isolate({
y() * input$num1 * input$num2
})
})
案例研究:使用 R 的 Shiny 建置網頁應用程式