我有以下 R Shiny 代码:
economics_points <- eventReactive(input$sigmaThresholdSlider, {
print("input$sigmaThresholdSlider fired.")
get_points(input$daterange, 1, input$sigmaThresholdSlider)
}, ignoreNULL = FALSE)
economics_points <- eventReactive(input$daterange, {
print("input$daterange fired.")
get_points(input$daterange, 1, input$sigmaThresholdSlider)
}, ignoreNULL = FALSE)
问题是 economics_points
仅在 daterange
控件更改时更新,而不是在 sigmaThresholdSlider
控件更改时更新。如果我颠倒这两个语句的顺序,economics_points
仅在移动 sigmaThresholdSlider
时更新。换句话说,第二条语句覆盖了第一条。
如何更改此代码,使其在调整任一个控件时运行?
documentation说 eventReactive
的 eventExpr
参数可以是“甚至是大括号内的复杂表达式”,但没有给出有用的示例。
最佳答案
通过给出一个列表似乎可行:
服务器
library(shiny)
shinyServer(function(input, output) {
view <- eventReactive(list(input$t1, input$t2),{
t1 <- input$t1
t2 <- input$t2
rnorm(1)
})
output$view <- renderPrint(view())
})
界面
library(shiny)
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
actionButton("t1", "t1"),
actionButton("t2", "t2")
),
mainPanel(
verbatimTextOutput("view")
)
)
))
关于R Shiny : eventReactive with two controls,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39170161/