Bogdan Rau
Bogdan Rau

Reputation: 625

Isolate no longer works since addition of eventReactive and observeEvent?

Previously, I had built a shiny dashboard with chart outputs that worked just fine and looked like the following:

output$someName <- renderGvis({
  input$inputButton

  data <- isolate(myData(function here))
  donut <- gvisDonut({...})

  return(donut)
})

Since the addition of observeEvent and eventReactive, I've not been able to get it to work the same as before. Essentially, the output$someName is a chart that is dependent on multiple inputs, and each time the user clicks on the inputButton, I need renderGvis to re-evaluate. The function should NOT re-evaluate when any of the other inputs change, just when the button is pressed.

I've had some luck getting observeEvent to run on input$inputButton click, however, each time I change any of my input parameters, the query is quickly rerun without having to press the button. Any takers here?

More detailed below:

output$someName <- renderGvis({
  input$inputButton

  data <- isolate(dataGrabber({})) # function that takes input and returns data frame using RMySQL

  isolate(simpleChart(data = data)) # simpleChart is a function to produce a gvisCalendar chart. 

Upvotes: 3

Views: 986

Answers (1)

Bogdan Rau
Bogdan Rau

Reputation: 625

OK...found an answer to this if anyone ever has this problem. The issue, which for some reason I had not encountered in the past, is that the isolate function now runs regardless of whether or not the value for actionButton is 0 or not. I believe in the past, it wouldn't run until actionButton had a value greater than 0.

The simple fix was:

output$someName <- renderGvis({
  input$inputButton
  if (input$inputButton == 0)
  return()

  isolate({ code to isolate})
})

Upvotes: 5

Related Questions