案例研究:使用 R 的 Shiny 构建 Web 应用
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 构建 Web 应用