R Shiny : eventReactive with two controls

标签 r shiny

我有以下 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 时更新。换句话说,第二条语句覆盖了第一条。

如何更改此代码,使其在调整任一个控件时运行?

documentationeventReactiveeventExpr 参数可以是“甚至是大括号内的复杂表达式”,但没有给出有用的示例。

最佳答案

通过给出一个列表似乎可行:

服务器

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/

相关文章:

r - Shiny 的传单添加大量分离的多段线

r - 如何访问分组过滤器操作的组 ID?

重复应用不同的列组合

JavaScript 错误 "Uncaught TypeError: Cannot call method ' push' of undefined"D3.js

json - 在 SHINY 中显示 HTTP GET 数据

r - Shiny 的仪表板操作按钮

r - 为什么不鼓励在 Shiny includeScript() 中使用绝对路径?

r - 确保在运行 .Rprofile 之前加载了所有默认包

r - 如何对聚合的输出进行排序?

r - 在 R Shiny 中处理输入数据集