R Shiny: Use reactiveValues() with data.table assign-by-reference

前端 未结 1 938
醉梦人生
醉梦人生 2021-01-13 17:19

I have a shiny app in which more than one reactive component uses the same result from a function that is slow to calculate. To avoid calculating the slow function more tha

相关标签:
1条回答
  • 2021-01-13 18:10

    say you have defined a reactive variable table_updated so you can increment it by one each time the slow function is done. Other values/plots will only need to observe table_updated.

    Actually the actionButton(see description section) does the same thing, every time it gets clicked, its value is incremented by 1.

    values <- reactiveValues(table_updated = 0)
    
    slow.func = function(my.dt, x) {
      # do stuff
      values$table_updated <- values$table_updated + 1
    }
    
    output$result2 = renderText({
      values$table_updated
      paste('Final value =', values$dt[100,]$v2)
    })  
    
    0 讨论(0)
提交回复
热议问题