【发布时间】:2018-08-01 13:16:48
【问题描述】:
我正在开发一个闪亮的应用程序,它在 eventReactive 函数中有一个带有多个 eventExpr 触发器的反应变量。有没有办法在 eventReactive 函数中放置一个 if 来改变反应变量是什么?例如,下面的代码 sn -p 描述了我想要做什么。如果更改了 input$Client,我希望将“dat”乘以它们当前的因子,包含在 y 中。如果按下操作按钮,我希望将“dat”乘以 input$Factor。有没有办法做到这一点?
ui = fluidPage(
selectInput(inputId = "Client", Label = "Choose Client",
choices = c("A", "B", "C", "D", "E")),
numericInput(inputId = "Factor", min = .5, max = 2, value = 1),
actionButton(inputId = "Reprice"),
dataTableOutput(outputId = "RepricedData")
)
server = function(input, output){
x = data.frame(rep(c("A", "B", "C", "D", "E"),20))
colnames(x) = "Client"
x$amount = runif(100, 50, 150)
y = data.frame(c("A", "B", "C", "D", "E"))
colnames(y) = "Client"
y$currentFactor = c(runif(5,.5,2))
rv = reactiveValues()
rv$repricedData = eventReactive(c(input$Client, input$Reprice), {
dat = x$amount[which(x$Client == input$Client)]
if(input$Client){
dat = dat * y$currentFactor[which(y$Client == input$Client)]
}else{
dat = dat * input$Factor
}
dat
})
output$repricedData = renderDataTable(
rv$repricedData()
)
}
shinyApp(server = server, ui = ui)
【问题讨论】:
-
是的!谢谢