Shiny Reactivity

I am trying to get this correct. Say I have a input table (rHandsontable) which all of its cells are editable. And I have another output dataTableOutput which will shows its values based on its values in the rHandsontable, after some formulae calculations. Any changes in values in the input rHandsontable should reflect the change in the output dataTableOutput.

How should I make use of Shiny Reactivity for this? Should I use observeEvent(input$rHandsontable_input)? But how would its outputs in dataTableOutput gets updated once there is some change in the input table?

I have used some kind of reactive function as below:

Updated_Outputs <- reactive({
## after loading in .RData file, which was generated from observeEvent(), then
## perform some formulae calculations, 
  Final_Outputs
  invalidateLater(10*1000)
  Final_Outputs
})

output$Outputs_table <- renderDataTable(Updated_Outputs())

which the reactive function has its updated .RData from the observeEvent(). This will work and its output does gets updated accordingly, but the problem is it gets updated and refreshed every 10 seconds. I do not want that to be refreshed using invalidateLater, but that it gets updated instantly using Shiny reactivity, once there is any change in the input rHandsontable.

Thanks.

Hi,

From what you've said it sounds like you shouldn't be needing to use observers at all. It isn't clear where your Final_Outputs is coming from or what the .RData file is, but it sounds like you should just have the data from the rhandsontable directly in the reactive, something like the below:

Updated_Outputs <- reactive({
  rhandsontable::hot_to_r(input$your_handsontable) %>%
    #...some calculations
})

output$Outputs_table <- renderDataTable(Updated_Outputs())

Just to note I don't have much experience with rhandsontable so you might have to access the data a little differently to input$your_handsontable.

Hope that helps.

Thanks Cnbrownlie for your inputs, it is helpful.
I actually use both reactiveVal and observeEvent, and it works. But I think your suggestion is neater and switch to your method.
Cheers

1 Like

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.